Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Answers for OCJP / SCJP Online Test - Online Exam - Online Quiz - Mock Test

←Go Back to Online Practice Test

Ques.

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();
    }
}


Option 1.

Animal

Option 2.

Cat

Option 3.

Animal Cat

Option 4.

Compile Error


Ans. Option 4

Please provide the reason below. The best provided reason will be displayed with your name(if you are logged-in) on website.
Enter Reason
 
Is it helpful? Yes No
©2024 WithoutBook