Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different packages and inheritance

 
Jason Attin
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, here is another question I'm not too sure about one of the answers (taken from Mock exam 3 on http://sybextestbanks.wiley.com/)

Which line in Tadpole give a compiler error?

A 5
B 6
C 7
D 8
E 9
F 10


I got two right, C and F but I didn't get E.

The explanation says about line 9:
Line 9 doesn't compile because the variable reference is to a Frog.


Still not sure I understand why it doesn't compile though. Can it not call because the variable reference is to a Frog? ould I possibly ask for a more detailed explanation please?

cheers
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll find an excellent explanation about the same question in this topic.
 
Henry Wong
author
Marshal
Pie
Posts: 22114
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was already explained in one of your earlier topics...

https://coderanch.com/t/669691/java/packages-protected-access

Henry
 
Narayana Bojja
Ranch Hand
Posts: 135
4
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I understand why it doesn't compile though. Can it not call
?
1
f.ribbit()
because the variable reference is to a Frog?


Yes. Your understanding is right. Frog, Tadpole are in different packages. Tadpole is extending Frog.  From Tadpole , you can access Frog members using Tadpole reference variable. You can't access using Frog  reference variable because Frog methods are protected , default which doesn't have scope out side the package. protected members are accessible through Sub class reference variable in other package.
You try to create object for Frog class and access Frog methods through that reference variable.Compiler will give errors. Here also same concept applies.

Hope this helps !
 
Jason Attin
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys, it's cleare now.
This was already explained in one of your earlier topics...
I missed that, sorry!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic