Frequent Questions      

  Java™ Certification: SCJP™ 6- Sun Certified Java Programmer Exam 

 

Java Classes

 

Home
           Up        Previous                 Next

Q4. Consider these classes, defined in separate source files, 

public class Test1{ 

public float aMethod(float a, float b) throws IOException{

}

}
1. public class Test2 extends Test1{
2.
3. }

Which of the following methods would be legal at line 2 in class Test2?

A. float aMethod(float a, float b){}

B. public int aMethod(int a, int b) throws Exception{ }

C. public float aMethod(float a, float b) throws Exception{ }

D. public float aMethod(float p, float q){ }

  Correct Answer: B, D

 

Explanation:

B and D are correct. B is legal as it is an example of method overloading. 

A is illegal because it is less accessible than the original method, because method in Test1 is public. And for any overriding method, accessibility must not be more restricted than the original method. 

C is illegal because for overriding method, it must not throw checked exception of classess that are not possible for the origincal classes.

Home
   Up           Previous                 Next

Copyright © 2000-2017 SimulationExams.com All rights reserved

Website design by Anandsoft.com

Disclaimer: All Simulation Exams practice tests, study guides and/or material are neither sponsored by, nor endorsed by, nor affiliated with Oracle® or any other company. All trademarks are trademarks of their respective owners and duly  acknowledged. OCA™, OCPJP™ are registered trade marks of Oracle® . The practice tests material is a copyright of SimulationExams.com and the same is not approved or endorsed by respective certifying bodies. Thank-you for your interest in Simulation Exams. Please see read me file before you download, install, and/or use any software from SimulationExams.com  For any information or questions regarding this Website, please e-mail webmaster at simulationexams.com