You are not logged in.

#1 2016-11-09 05:56:40

Muhammad
User RankUser RankUser RankUser RankUser RankUser Rank
بِسمِ اللَّهِ الرَّحمٰنِ الرَّحيمِ
From: Sahiwal Division
Registered: 2012-03-22
Posts: 22,197
Website

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/

2016-11-09 05:56:40

Advertisement
Ads By Google

Re: What is the output for the below code?



\n

Board footer