Javatpoint Logo

what is the use of virtual keyword in java

By: rajivs*** On: Fri May 30 09:50:38 IST 2014     Question Reputation3 Answer Reputation0 Quiz Belt Series Points0  3Blank User
What is virtual keyword in java and uses of virtual keyword?Up3Down

 

Although Java does NOT have a virtual keyword, Java has virtual functions and you can write them.

In object-oriented programming, a virtual function or virtual method is a function or method whose behaviour can be overridden within an inheriting class by a function with the same signature. This concept is a very important part of the polymorphism portion of object-oriented programming (OOP).
Image Created0Down

By: [email protected] On: Fri May 30 12:48:05 IST 2014 Question Reputation0 Answer Reputation392 Belt Series Points0 392User Image
Are You Satisfied :2Yes1No
 
Java does not have a virtual keyword because all non-static methods use dynamic binding and and therefore are be default virtual. In Java, the programmer doesn't have to decide whether to use dynamic binding.
In Java you do not need to use any keyword like virtual or override since by default all non static functions are considered as virual. You have to make it either private or use final keyword to remove the default virtual feature in each function in the Java classes.
Image Created0Down

By: [email protected] On: Sat May 31 10:06:17 IST 2014 Question Reputation0 Answer Reputation359 Belt Series Points0 359User Image
Are You Satisfied :2Yes0No