Home Tutorial Java Scjp Part4 SCJP Module-4 Question-14

 
 

SCJP Module-4 Question-14
Posted on: July 10, 2010 at 12:00 AM
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)

Related Tags for SCJP Module-4 Question-14:


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.