Java Overriding


Method Overriding

Method overriding achieved by the same method and the same parameter in base class as well as in derived class. Method overriding used only in different classes.

Syntax:

 class A {  
	public:  
		void show(){
         //body of the function. 
        }    
}
class B {  
	public:  
		void show(){
         //body of the function. 
        }    
} 
Java function overriding

Example:

 class A // base class
{    
    void showdata()
    {
        System.out.println("Base class");  
	}
}
class B extends A // derived class
{  
	void showdata()
    {
        System.out.println("Derived class");  
	}
}       
public class Methodoverriding{  
    public static void main(String args[])
    {  
        B b=new B();  
        b.showdata(); 
    }
}



Onlinetpoint is optimized for basic learning, practice and more. Examples are well checked and working examples available on this website but we can't give assurity for 100% correctness of all the content. This site under copyright content belongs to Onlinetpoint. You agree to have read and accepted our terms of use, cookie and privacy policy.