GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java

 Print  |  
Question:  Overriding Methods

Answer: Suppose a Super Class method throws an exception and this method is Overriden in the subclass with no exception. Now if you create a super class reference that has a subclass object. This throws a compile time error, Why?


May 05, 2009 23:25:41 #10
 inthiyaj   Member Since: May 2009    Total Comments: 4 

RE: Overriding Methods
 
In this case we are calling a method with super class reference and sub class object. Super class reference can call only the methods which it knows (its knowledge) and execute sub class's defined method. So while we are calling method Super class has the knowledge that this method will throw an exception and need to handle this. Because of this the compiler shows error.
Thanks,
     

 

Back To Question