Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java reference types

 
Adi Sharma
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am preparing for SCJP and was reading the :

" method invocations allowed by the compiler are based solely on
the declared type of the reference, regardless of the object type. "

could anyone explain what it means ???

Thanks
Aditya Sharma
 
Campbell Ritchie
Sheriff
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that when you declare

Foo fff;
. . .
fff = new FooFoo(123, "abc");
. . .
fff.baa();

the compiler will only allow that baa() call if the Foo class has a method called baa. If the Foo class hasn't and the FooFoo class has, then the compiler will not allow that code to be compiled.
 
Adi Sharma
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
Campbell Ritchie
Sheriff
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Peter Granstrom
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your answer,
it helped me
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic