Method Overriding In Java

When a function with the same name and in the base and derived class is there then the base class function will be overridden(Means Ignored.

Example of Method Overriding:

class A
{  
 void Hello()
{
System.out.println("Hello from class A");
}  
}  
class B extends A
{  
  void Hello()
{
System.out.println("Hello from class B");
}  
  
  public static void main(String args[])
{  
  B b1 = new B();  
  b1.Hello(); 
  }  
}  
Output:
Hello from class B

 

Leave a Reply