• Post Reply Bookmark Topic Watch Topic
  • New Topic

code doubts  RSS feed

 
Kamila Bertran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there!
Could someone kindly explain me why the below code will fail?

 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kamila Bertran wrote:
Could someone kindly explain me why the below code will fail?


Can you explain what you mean by "fail"? Do you mean that it will not compile? If so, wouldn't it be a good idea to tell us what the compile error is? And what you think is the cause first?

Henry
 
Tim Cooke
Marshal
Posts: 3873
233
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it fail? Have you run it? What happened when you run it?
 
Kamila Bertran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it doesn't compile.

Compile error: can't find symbol - variable playMovie
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kamila Bertran wrote:
Compile error: can't find symbol - variable playMovie


... and does a Phone reference have access to the playMovie field?

Henry
 
Kamila Bertran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's seems to be the issue and something I keep getting lost on. Would you know any source that could explain to me better the interdependence between reference type and the object type?
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you've declared "phone" to be of type "Phone", you can only access methods and members that have been defined in "Phone". "Tablet" is-a "Phone", but has added some of its own members. "phone" does not have access to members that are specific to "Tablet", only those members that are common to both "Phone" and "Tablet".
 
Kamila Bertran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So in other words if I have a class Phone, an it's two subclasses Tablet and SmartPhone and want to gather them all in an ArrayList<Phone> I won't be able to refer to Tablet & SmartPhone specific methods ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not without casting.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!