Welcome Guest | Sign in | Register
Declarations and Access Control - Discussion Page For Q.2589 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Exercise:

Section 1

Q:  What will be the output of the program?
class Super{
public Integer getLength(){
return new Integer(4);
}
}

public class Sub extends Super{
public Long getLength(){
return new Long(5);
}

public static void main(String[] args){
Super sooper = new Super();
Sub sub = new Sub();
System.out.println(
sooper.getLength().toString() + "," + sub.getLength().toString() );
}
}
A. 4, 4 B. 4, 5
C. 5, 4 D. Compilation fails.

Answer and Explanation

Answer:Compilation fails.

Explanation:
Option D is correct, compilation fails - The return type of getLength ( ) in the super class is an object of reference type Integer and the return type in the sub class is an object of reference type Long.
In other words, it is not an override because of the change in the return type and it is also not an overload because the argument list has not changed.  

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.