Home Tutorial Java Scjp Part1 SCJP Module-1 Question-10

 
 

SCJP Module-1 Question-10
Posted on: July 7, 2010 at 12:00 AM
The program given below heps in understanding of inheritance in core java and helpful for SCJP examination

Given a sample code:

1 class Base {
2 public void method(int i) {
3 System.out.println("Value of i is " + i);
}}

4 public class SubClass extends Base {
5 public void method(int j) {
6 System.out.println("Value of j is " + j);
}

7 public static void main(String args[]) {
8 SubClass s = new SubClass();
9 s.method(1);
}}

What will be the result of above code ?

(1)    Value of i is 1        

(2)    Value of j is 1     

3)    Compilation error at line number 5

(4)   Compilation error at line number 8

Answer

(2)

Explanation:

It prints the value of j is 1 because of overriding property.

Related Tags for SCJP Module-1 Question-10:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.