Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 58

Given:

What is the result?

    Correct Answer: C

    The code will fail to compile. In the line 'ac = sc;', we are trying to assign a reference of type SomeClass to a variable of type AnotherClass. This is not allowed without an explicit cast, because a superclass reference cannot be directly assigned to a subclass reference; it needs explicit downcasting.

Discussion
aruni_mishraOption: C

C. superclass reference cannot be assigned to subclass reference without explicit cast.

mrc61Option: B

SomeClass cannot be converted to AnotherClass C. public class q58 { public static void main(String[] args) { AnotherClass ac = new AnotherClass(); SomeClass sc = new AnotherClass(); ac = sc; // sc = ac; sc.methodA(); ac.methodA(); } } class SomeClass { public void methodA() { System.out.println("Some Class #methodA ()"); } } class AnotherClass extends SomeClass { public void methodA() { System.out.println("AnotherClass#methodA() "); } }

mendjijetOption: C

C is correct

d7bb0b2Option: C

C is correct, child variable cannot be a parent reference

OmnisumemOption: C

Tested: C.

tmuralimanoharOption: C

Answer: C

StavokOption: C

C is Correct Type mismatch: cannot convert from SomeClass to AnotherClass

RP384Option: C

child type cannot hold parent type reference

Ankit1010Option: C

C is the correct answer; Required type: AnotherClass Provided: SomeClass

TADIEWAOption: C

c , child type cannot hold parent type reference , incompatible types .... but a parent type reference can hold up child type reference