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?


August 08, 2008 23:24:05 #3
 r.praveenkumar   Member Since: October 2007    Total Comments: 27 

RE: Overriding Methods
 
Just now consider the method in super class do not throw any exception If we are assigning the object of subclass to super class reference and if we invoke the method using that reference the compiler will check whether that method is available in the super class since we are invoking the method only using the super class reference and if it is there then the prog successfully compiles but during execution JVM runs only the sub class version of the method. this is polymorphism.
     

 

Back To Question