Object Oriented Programming : interface

We can keep a group of methods without any body in an interface.

Usually these are related methods.

We created here one interface games. Inside games we kept outdoor, indoor methods.

Note that here we have used class game_types by using the keyword implements ( not used the keyword extends )
package Pack1;

public class my_interface {
	interface games{
		public void outdoor();
		public void indoor();
	}

	static class game_types implements games{
		public void outdoor() {
			System.out.println("Cricket");
		}
		public void indoor() {
			System.out.println("Table Tennis");
		}
	}
	  public static void main(String[] args) {
		    game_types my_game=new game_types();
		    my_game.outdoor();
		    my_game.indoor();
	  }
}
Output is here
Cricket
Table Tennis
We can change the above code like this ( removed static )
package Pack1;

interface games{
	public void outdoor();
	public void indoor();
}

 class game_types implements games{
	public void outdoor() {
		System.out.println("Cricket");
	}
	public void indoor() {
		System.out.println("Table Tennis");
	}
}

public class my_interface {

	  public static void main(String[] args) {
		    game_types my_game=new game_types();
		    my_game.outdoor();
		    my_game.indoor();
	  }
}




plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer