Java Program to Implement Interface Mango in Summer and Winter

Write a Java program to implement Interface Mango in Summer and Winter.



Source Code
//Creating interface 'Mango' having display( ) method.
interface Mango {
	
	void display();
}

//Implementing interface 'Mango'.
class Summer implements Mango {
	
	// Overriding 'display( )' method.
	public void display() {
		
		System.out.println("Display method in Summer ... ");
	}
}

//Implementing interface 'Mango'.
class Winter implements Mango {
	
	//Overriding 'display( )' method.
	public void display() {
		
		System.out.println("Display method in Winter ...");
	}
}

class MyInterface {
	
	public static void main(String args[]) {
		
		Mango m = new Summer(); //statement1
		Winter n = new Winter();
		m.display();
		m = n; //assigning the reference
		m.display();
	}
}
Output
Display method in Summer ... 
Display method in Winter ...