Home > Java > Java Program to show Overriding Methods – Q22

Java Program to show Overriding Methods – Q22

January 11, 2009 Leave a comment Go to comments

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):


Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: