Given:
What is the result?
Given:
What is the result?
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.
C. superclass reference cannot be assigned to subclass reference without explicit cast.
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() "); } }
C is correct
C is correct, child variable cannot be a parent reference
Tested: C.
Answer: C
C is Correct Type mismatch: cannot convert from SomeClass to AnotherClass
child type cannot hold parent type reference
C is the correct answer; Required type: AnotherClass Provided: SomeClass
c , child type cannot hold parent type reference , incompatible types .... but a parent type reference can hold up child type reference