Given:
What is the
result?
public class AnotherSampleClass extends SampleClass {
public static void main(String[] args) {
Object obj = new
AnotherSampleClass();
System.out.println("sc: " + obj.getClass().getName());
System.out.println("asc: "
+
((AnotherSampleClass) obj).getClass().getName());
}
}
public class SampleClass {
}
A.
sc: java.lang.Object
asc: AnotherSampleClass
sc: java.lang.Object
asc: AnotherSampleClass
B.
sc: SampleClass
asc: AnotherSampleClass
sc: SampleClass
asc: AnotherSampleClass
C.
sc: AnotherSampleClass
asc: SampleClass
sc: AnotherSampleClass
asc: SampleClass
D.
sc: AnotherSampleClass
asc: AnotherSampleClass
sc: AnotherSampleClass
asc: AnotherSampleClass
RispostaD.
Il riferimento di obj è AnotherSampleClass e quindi stampa sempre AnotherSampleClass.
Nessun commento:
Posta un commento