What is the result?

Given:
What is the result?

Given:
What is the result?

A.
sc: class.Object
asc: class.AnotherSampleClass

B.
sc: class.SampleClass
asc: class.AnotherSampleClass

C.
sc: class.AnotherSampleClass
asc: class.SampleClass

D.
sc: class.AnotherSampleClass
asc: class.AnotherSampleClass

Explanation:

Note: The getClass method Returns the runtime class of an object. That Class object is the object
that is locked by static synchronized methods of the represented class.
Note: Because Java handles objects and arrays by reference, classes and array types are known as
reference types.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Miguel

Miguel

public class SampleClass {
public static void main(String[] args) {
AnotherSampleClass asc = new AnotherSampleClass();
SampleClass sc = new SampleClass();
sc = asc;
System.out.println(“sc: ” + sc.getClass());
System.out.println(“asc: ” + asc.getClass());
}
}

class AnotherSampleClass extends SampleClass {
}

sully

sully

“xception in thread “main” java.lang.Error: Unresolved compilation problems:
Syntax error on tokens, delete these tokens
The operator + is undefined for the argument type(s) Class
Syntax error on tokens, delete these tokens
The operator + is undefined for the argument type(s) Class”

Miguel thanks for putting up the code.
Seems to cause problems and doesn’t work. So sc takes on same value as asc

nisha

nisha

I was able to execute Miguel’s code and got the following result:

sc: class AnotherSampleClass
asc: class AnotherSampleClass