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
Post a Comment