Learn Java Overriding Method #java

preview_player
Показать описание
#Java #javaprogramming #javatutorial #javaforbeginners #overriding
In this video we learn about what overriding methods in java. Here I explain with simple example.

Overriding Methods
___________________
Super class and Sub class have same methods.
Sub class methods override the Super class methods.
By overriding java implements run time polymorphism.
The methods argument are identical for both super class and sub class.
The Methods return type also identical for super class and sub class.
Program
_________
class sup {
void display(String x)
{
}
class sub extends sup{
void display(String y)
{
}
}
class sample
{
public static void main(String args[])
{
sub obj= new sub();
_______________________________________________________________________
Dynamic Mthods Dispatch
_________________________
By Super Class Object reference we resolve dynamic methods. Using Super Class object reference we call sub class or super class methods.
Example Program
________________
class sup {
void display(String x)
{
}
class sub1 extends sup {
void display(String y)
{
}
}
class sub2 extends sub1 {
void display(String z)
{
}}
class sample_overriding
{
public static void main(String args[])
{
sup supref ;
sup obj_super= new sup();
sub1 obj1 = new sub1();
sub2 obj2 = new sub2();
supref = obj1;
supref = obj2;
supref=obj_super;
}}
Her we use super class object reference to sub class object.
Super class reference object call correct version of sub class.
This we use Dynamic method Binding or Runtime polymorphism.
----------------------------------------------------------
Other Video Link
------------------
How to compile and run java program in notepad
Program to print welcome to java:
Overloading Methods:
Рекомендации по теме
visit shbcf.ru