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

Java Program to show Overriding Methods – Q22


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


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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: