parctice program Scenario 2:

Expected Understanding: Interface, Class, static variables, dynamic binding

1) Create an interface called ‘Actor’
– Have variables boolean makeUpRequired
– Assign ‘true’ value for ‘makeUpRequired’
– Have variable String address.
– Assign value as “Chennai” to address.
– Have void methods act(), dance(), sing()

interface Actor
{
boolean makeuprequired = true;
String address = "Chennai";

public void act();


public void dance();


public void sing();

}

2) Create class named as ActorSivakumar with main method
– implement interface ‘Actor’ to this class.
– Give your own definitions for methods from interface
– Have static variable String address.
– Assign value to address as “Coimbatore”.
– Have instance method ‘speaking()’ with void return data type.
– Create instance for ActorSivakumar as below
ActorSivakumar as = new ActorSivakumar(65, “Audi Car”)
– Handle with proper Constructor
– Access all the methods from ActorSivakumar class
– Access variable address and print the value
– Create another instance of interface ‘Actor’ using dynamic binding approach
Actor ac = new Sivakumar();
– Handle with proper Constructor
– Access methods in ActorSivakumar class.
– Access variable address using ‘ac’ intance and print the value
– Observe and note down the difference between two instances







public class ActorSivakumar implements Actor
{

static String address ="Coimbatore";
int age;
String name;

public ActorSivakumar()
{
	System.out.println("HI");
}

	public ActorSivakumar(int age,String name)
	{
		this.age=age;
		this.name=name;
		System.out.println(" age " + this.age + " name "+ this.name);
	}




	public static void main(String[] args) 
	{
	ActorSivakumar as = new ActorSivakumar(65,"audicar");
	as.speaking();
	as.act();
	as.dance();
	as.sing();
	Actor ac = new ActorSivakumar();
	//ac.speaking();
	ac.act();
	ac.dance();
	ac.sing();

	}
	public void act()
	{
		System.out.println("act");
	}
    public void dance()
    {
    	System.out.println("dance");
    }
	public void sing()
	{
		System.out.println("sing");
	}
	public void speaking()
	{
		System.out.println("speak");
	}
	


}

Leave a Comment