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

Overriding

 
sandhi mridul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
there are 2 programs only diffre in the static n non static.


Ans= Base.test()

another code



ans= Child.test()

My question is why the calling method class is getting change means at one place its Base class however at other its child class. What is the reason behind.

please explain me the how the call is going for a static method and nonstatic method?

Thanks
Sandhya
 
Sergio Calvo
Greenhorn
Posts: 8
 
Chethan C Gowda
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While calling static methods compiler checks for reference type not the obect type.
In example 1 you are calling static method using Base class reference, where as while calling instance method compiler checks for object type.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic