0

Netbeans extent Convert help

*(the classes Doctor and Teacher extends Person) Person p1=new Doctor(); How can I Convert p1 to a Teacher or only a person?

25th Mar 2019, 4:10 PM
Omer Kori
Omer Kori - avatar
1 ответ
+ 5
You can not convert p1 to Teacher as they are sibling classes, but you can cast p1 to person like this: Person p2 = (Person) p1;
25th Mar 2019, 4:24 PM
Letsintegreat
Letsintegreat - avatar