Topics Index

Creating object for class1618

If you need explanation Read this topic

If you need Answer Take test on this topic

Creating object for class1618
What is the output of the program?
public class DemoOnEmployee {
    public static void main(String args[]) {
        class Employee {
            public String name;
            public Employee(String name) {
       = name;
            public String getName() {
                return name;
        Object object = new Employee("Merit Campus");

A. Merit Campus
B. Compilation Error hence Employee class created in main() method
C. Compilation Error due to other reasons
D. Runtime Error
Topic: Advanced Java Programming Concepts

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans :a
object cls is basic can be used for any objects
so it can be used for employees class

Posted by Ananda Kumar    2014-04-18 13:16:53

Ans is C. Compilation error occurs due to getName() method not defined in Object class and referring through object of Object type.

Posted by Nikhil Sulibhavi    2014-04-18 13:20:20

Ans is C.. parent class Object vl nt contain the getName() method which is to be override.. so it leads compilation error for without having getName method in Object class..

Posted by Om Prakash Om    2014-04-18 13:24:19

Compiler throws an error here. Parent class reference can be used to hold a child class object. By using that reference, we can only call methods available in the parent class. Child-specific methods cannot be called. Here getName() is specific to Employee. So, the answer is C.

Posted by Shaileshwar Sharma    2014-04-20 17:21:49

Congratulations Nikhil Sulibhavi. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-21 04:12:12

© meritcampus 2019

All Rights Reserved.

Open In App