throw user defined exception in single statement in java -


recently attended interview. 1 of questions asked in technical interview round "how can throw user defined exception using single statement". wrote code as

class myexception extends exception{ public myexeption(string err){ super(err); } class sample{ public static void main(string a[]){ throw new myexception("error"); } 

but said used 2 statements 1 throw statement , other super() statement. answer. plese clear doubt. thank you

i sure interviewer looking extend exception anonymously:

throw new exception("error") {     // here makes exception user-defined.     // not need override anything, if want, can:     public string getmessage() {         return "here user-defined exception!";     } }; 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -