java - How come when I cast down I cannot access the subclass properties? -


class casting {     main()     {         //instantiate subclass motox         cellphone myphone = new motox("motorola", "white", true, 5);         motox phone = (motox) myphone;         //i tried call motox methods using myphone          //however netbeans showed properties within cellphone class     } } 

i know down cast serves convert, if will, super class more specific subtype, when don't gain access motox class' properties.

myphone defined cellphone. if want use motox methods, should either define motox:

motox myphone = new motox("motorola", "white", true, 5); 

or explicitly cast when use it:

cellphone myphone = new motox("motorola", "white", true, 5); ((motox) myphone).somemotoxmethod(); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -