1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 58


Given:

What is the result?

Show Answer
Correct Answer: BC

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

10 comments
Sign in to comment
TADIEWAOption: C
Dec 26, 2022

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

Ankit1010Option: C
Feb 2, 2023

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

RP384Option: C
Feb 9, 2023

child type cannot hold parent type reference

StavokOption: C
Jun 7, 2023

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

tmuralimanoharOption: C
Jun 29, 2023

Answer: C

OmnisumemOption: C
Sep 5, 2023

Tested: C.

d7bb0b2Option: C
Dec 9, 2023

C is correct, child variable cannot be a parent reference

mendjijetOption: C
Feb 8, 2024

C is correct

mrc61Option: B
Mar 23, 2024

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() "); } }

aruni_mishraOption: C
Jun 19, 2024

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