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

help in overridding and overloading ?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please consider the following paragraph from kb6 book page no. 115, table 2-3

Reference type determines which overloaded version (based
on declared argument types) is selected. Happens at compile
time. The actual method that’s invoked is still a virtual method
invocation that happens at runtime, but the compiler will
already know the signature of the method to be invoked. So at
runtime, the argument match will already have been nailed
down, just not the class in which the method lives.


what does it mean? specifically what is "virtual method" ? secondly what does the last line means when the author says "nailed down, just not the class in which the method lives" ?
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At compile time, it detects which overloading method to be invoked for the given reference (The reference on which the method gets called). Runtime determines which class' method should be called. This depends on the object referred to by the reference.

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a side note : in Java non-static,non-final and non-private methods are virtual by default.

and Yes *just not the class in which the method lives* this sentence is bit confusing

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gurpeet singh wrote:specifically what is "virtual method" ?

try googling
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks John and Seetharaman.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gurpeet singh wrote:thanks John and Seetharaman.

You are welcome
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is virtual method a C++ term?
I think virtual method is abstract method that has not implementation and is overriden.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Helen Ma wrote:Is virtual method a C++ term?
I think virtual method is abstract method that has not implementation and is overriden.

I dont know whether virtual born from c++ or not but definitely it an OOP term.

virtual method not necessarily to be an abstract. any method that can be overridden is a virtual method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic