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

 
 

Share on Google+Share on Google+
SCJP Module-4 Question-15
Posted on: July 10, 2010 at 12:00 AM
Advertisement
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.

 

Advertisement

Related Tags for SCJP Module-4 Question-15:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 10, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com