Home Tutorial Java Scjp Part2 SCJP Module-2 Question-10

 
 

SCJP Module-2 Question-10
Posted on: July 8, 2010 at 12:00 AM
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.

Related Tags for SCJP Module-2 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.