SCJP Module-4 Question-15


 

SCJP Module-4 Question-15

The program given below tests your understanding of inheritance and, function overloading and function overriding in Java.

The program given below tests your understanding of inheritance and, function overloading and function overriding in Java.

Given below the sample code :

class SuperClass1
{
private void m1()
{
System.out.println("SuperClass's m1()");
}
public void m2()
{
System.out.println("SuperClass's m2()");
m1();
}
}
class Modify extends Superclass
{
public void m1()
{
System.out.println("Modify's method1()");
}
public static void main(String args[])
{
SuperClass1 s = new Modify();
s.m2();
}
}

What will be the output of the following :

1. Prints : SuperClass's m1()

2. Prints : SuperClass's m2()

3. Error in compilation.

4.  Prints : SuperClass's m1()  SuperClass's m2()

Answer :

(3)

Explanation :

Type mismatch: cannot convert from Modify to SuperClass1.

 

Ads