You are not logged in.
Pages:: 1
#1 2016-11-09 05:56:40
What is the output for the below code?
Java Quizzes Sun Certified Java Programmer (SCJP)
Question:
What is the output for the below code?
package com;
class Animal {
public void printName(){
System.out.println(“Animal”);
}
}
package exam;
import com.Animal;
public class Cat extends Animal {
public void printName(){
System.out.println(“Cat”);
}
}
package exam;
import com.Animal;
public class Test {
public static void main(String[] args){
Animal a = new Cat();
a.printName();
}
}
Options are
Option A):
Compile Error
Option B):
Animal Cat
Option C):
Cat
Option D):
Animal
Correct Answer is Option A):
Compile Error
Explanation:
Cat class won’t compile because its superclass, Animal, has default access and is in a different package. Only public superclass can be accessible for different package.
Online Web Tutorials And Interview Questions With Answers Forum:
https://globalguideline.com/forum/
Offline
2016-11-09 05:56:40
- Advertisement
- Ads By Google
Re: What is the output for the below code?
\n
Pages:: 1