SCJP Module-4 Question-14


 

SCJP Module-4 Question-14

The program given below checks you knowledge of function and constructor in core Java and it is very helpful for SCJP exam preparation.

The program given below checks you knowledge of function and constructor in core Java and it is very helpful for SCJP exam preparation.

Given below the sample code :

class Superclass {
int i = 30;
public void function()
{
System.out.println("Superclass.function()");
}
Superclass()
{
function();
}
}
public class Subclass extends Superclass
{
int i = -1;
public static void main(String argv[])
{
Superclass b = new Subclass();
System.out.println(b.i);
b.function();
}
public void function()
{
System.out.println("Subclass.function()");
}
}

What will be the output of the following code ?

1. Subclass.function()   Subclass.function()

2. Subclass.function()   -1    Subclass.function()

3. Subclass.function()    30   Subclass.function()

4. Compile error

Answer :

(30)

Ads