answer : C
Conversion of Reference Types
Downcasting
It’s the casting from a superclass to a subclass.
An explicit cast is required.
llegitimate narrowing results in a ClassCastException.
ac = (AnotherClass)sc; throw runtime ClassCastException
ac = sc; Compilation eror error: incompatible types:
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 , child type cannot hold parent type reference , incompatible types .... but a parent type reference can hold up child type reference
upvoted 1 times
...
This section is not available anymore. Please use the main Exam Page.1z0-819 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
11 months agoaruni_mishra
1 year agomrc61
1 year, 3 months agomendjijet
1 year, 4 months agod7bb0b2
1 year, 6 months agoOmnisumem
1 year, 10 months agotmuralimanohar
2 years agoStavok
2 years agoRP384
2 years, 4 months agoAnkit1010
2 years, 5 months agoTADIEWA
2 years, 6 months ago