Tuesday, July 8, 2014

Overriding concept in java

import java.io.*;
class overridding
{
//over riding is the concept in which the derived classes also contain member function of same names and differ in no. or type of parameters..
public static void main(String[] args)
{
System.out.println("in main function");
derived3 d3=new derived3();
d3.function();
d3.function(5);
d3.function(5,10);
}
}
class base
{
void function()
{
System.out.println("in base function");
}
}
class derived2 extends base
{
void function(int a,int b)
{
System.out.println("in 1st derived function");
}
}
class derived3 extends derived2
{
void function(int x)
{
System.out.println("in 2 nd derived function");
}
}

No comments:

Post a Comment