SCJP Module-2 Question-10


 

SCJP Module-2 Question-10

This program heps in understating of methods and also gives the knowledge of hoe the methods can be called.

This program heps in understating of methods and also gives the knowledge of hoe the methods can be called.

What is the output of the following code:

public class Example10 {
public static void main(String[] argv) {
SubExample2 se = new SubExample2();
se.showTitle();

}
}

class SubExample1{
String Name;

public SubExample1(String n) {
Name = n;
}

public void showName() {
System.out.println("Name is " + Name);
}
}

class SubExample2 extends SubExample1 {
public void setName(String nn) {
Name = nn;
}
}

What is the output of the above given code :

1  n

2. nn

3. null

4. Unresolved compilation problem:

Answer :

(4)

Explanation :

Since constructor of the SubExample1 class has a parameterized constructor that's why the "Name" value is undefined in this case.

Ads