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

 
 

SCJP Module-1 Question-9
Posted on: July 7, 2010 at 12:00 AM
A program given below helps in understating of Inheritance in core java and refreshes the concepts of core Java 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 Base b1 = new Base();
9 Base b2 = new SubClass();
10 b1.method(1);
11 b2.method(2);
}}

What will be the result?

(1)    Value of i is 1
         Value of j is 2

(2)    Value of i is 1
         Value of j is 1

(3)    Value of i is 2
         Value of j is 2

(4)    Value of i is 2
         Value of j is 1

Answer

(1)

Related Tags for SCJP Module-1 Question-9:


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.