Menu
Topics Index
...
`

Get book


If you need explanation Read this topic

If you need Answer Take test on this topic

Get book
What will be the output of the following program?
class Book {
}
public class NoteBook {
    public static void main(String[] args) {
        Class myBook;
        Book b1 = new Book();
        NoteBook b2 = new NoteBook();
        myBook = b2.getClass();
        System.out.println(myBook.getSuperclass());
    }
}

A. class NoteBook
B. class Book
C. Some other output
D. Compilation Error
E. Runtime Error
Topic: java.lang.class - Java Library

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.

D because myBook variable holds class of Notebook() but it does not extend any class so compile time error at myBook.getSuperclass()

Posted by Ramkumar Boggarapu    2014-02-07 04:02:49


ans is D...bcz myBook is not a clsss..so we can't get super class

Posted by Ashok Reddi    2014-02-07 04:03:52


Ans is :C , Because myBook obj is stores NoteBook class, myBook reference type is 'Class' and its super class is 'Object'. so output is: " class java.lang.Object ".

Posted by Mallikarjuna Rao    2014-02-07 04:56:02


Ans is b coz mybook.getsuperclass() function returns class book

Posted by Lavanya Kategaru    2014-02-07 12:05:56


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

Posted by Merit Campus    2014-02-10 04:00:23


© meritcampus 2019

All Rights Reserved.

Open In App