Archive

Posts Tagged ‘Method Overriding’

Java Program to show Overriding Methods – Q22

January 11, 2009 Leave a comment

Q22: Java Program to show over-riding methods

Method Overriding allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super classes or parent classes.

class base_cl{
	public void test(){
		System.out.println("Function test called of Base class");
	}
}

class derived_cl extends base_cl{
	public void test(){
		System.out.println("Function test called of Derived 
    class");
	}
}

class over_ride{
	public static void main(String args[]){
		
		System.out.println("\n Base class Instanciated.");
		base_cl Ob = new base_cl();
		Ob.test();
		
		System.out.println("\n Derived class Instanciated.");
		derived_cl Od = new derived_cl();
		Od.test();
	}
}

… from College notes (BCA/MCA assignments):