Question: Suppose you have a reference variable named thing, youre not sure what type of object it points to, and you want your program print out

Suppose you have a reference variable named thing, you’re not sure what type of object it points to, and you want your program print out its type. The Object class (and therefore any class!) has another method, getClass, that returns a special object of type Class that contains information about the class of the object calling the getClass method. The Class class has a method called getName which returns the name of the class described by its calling object. Write a statement that prints the name of thing’s class.

Step by Step Solution

3.39 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Sure you can use the getClass method from the Object class to retrieve the ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction To Programming With Java A Problem Solving Approach Questions!