Defining Laughter

If laughing means using the same syllable twice, let's make this explicit in the class.

Defining Laughter

If laughing means using the same syllable twice, let's make this explicit in the class.

Defining Laughter

If laughing means using the same syllable twice, let's make this explicit in the class.

Defining Laughter

If laughing means using the same syllable twice, let's make this explicit in the class.

Defining Laughter

If laughing means using the same syllable twice, let's make this explicit in the class.

Defining Laughter

We have a simple program that allows us to go "haha", but what happens if we want to laugh differently ?

Defining Laughter

We have a simple program that allows us to go "haha", but what happens if we want to laugh differently ?

Defining Laughter

We have a simple program that allows us to go "haha", but what happens if we want to laugh differently ?

Defining Laughter

We have a simple program that allows us to go "haha", but what happens if we want to laugh differently ?

Defining Laughter

We have a simple program that allows us to go "haha", but what happens if we want to laugh differently ?

Defining Laughter

So we have to make the laugh() method use a parameter

Defining Laughter

So we have to make the laugh() method use a parameter

Defining Laughter

So we have to make the laugh() method use a parameter

Defining Laughter

So we have to make the laugh() method use a parameter

Defining Laughter

So we have to make the laugh() method use a parameter

Defining Laughter

We could make a default kind of laughter which will be used if the calling class doesn't explicitly state what sort of laughing to do. We can do this by overloading the laugh() method.

Defining Laughter

We could make a default kind of laughter which will be used if the calling class doesn't explicitly state what sort of laughing to do. We can do this by overloading the laugh() method.

Defining Laughter

We could make a default kind of laughter which will be used if the calling class doesn't explicitly state what sort of laughing to do. We can do this by overloading the laugh() method.

Defining Laughter

We could make a default kind of laughter which will be used if the calling class doesn't explicitly state what sort of laughing to do. We can do this by overloading the laugh() method.

Defining Laughter

We could make a default kind of laughter which will be used if the calling class doesn't explicitly state what sort of laughing to do. We can do this by overloading the laugh() method.

Defining Laughter

Instead of being stuck with "haha", we could tell the Laugher object when it is created what kind of laughter to use as a default.

Defining Laughter

Instead of being stuck with "haha", we could tell the Laugher object when it is created what kind of laughter to use as a default.

Defining Laughter

Instead of being stuck with "haha", we could tell the Laugher object when it is created what kind of laughter to use as a default.

Defining Laughter

Instead of being stuck with "haha", we could tell the Laugher object when it is created what kind of laughter to use as a default.

Defining Laughter

Instead of being stuck with "haha", we could tell the Laugher object when it is created what kind of laughter to use as a default.

Defining Laughter

Instead of being stuck with "haha", we could tell the Laugher object when it is created what kind of laughter to use as a default.

Defining Laughter

Instead of being stuck with "haha", we could tell the Laugher object when it is created what kind of laughter to use as a default.

Defining Laughter

But parameters only exist while the method is executing! And they can only be seen in their own method! So how can laugh() get to see the value of defaultSyl ???

Defining Laughter

Answer: we can provide memory for objects in the form of instance variables .

Defining Laughter

Answer: we can provide memory for objects in the form of instance variables .

Defining Laughter

Answer: we can provide memory for objects in the form of instance variables .

Defining Laughter

Answer: we can provide memory for objects in the form of instance variables .

Defining Laughter

Answer: we can provide memory for objects in the form of instance variables .

Defining Laughter

Answer: we can provide memory for objects in the form of instance variables .

Defining Laughter

Answer: we can provide memory for objects in the form of instance variables .

Defining Laughter

Instance variables belong to the object and can be used by any of the object's methods. They are declared outside any of the methods and provide memory (state) for the object. They will typically be initialised by the constructor.

Defining Laughter

Of course, if you want to be really lazy, the default constructor must do all the initialising by itself!

Defining Laughter

Of course, if you want to be really lazy, the default constructor must do all the initialising by itself!

Defining Laughter

Of course, if you want to be really lazy, the default constructor must do all the initialising by itself!

Defining Laughter

Of course, if you want to be really lazy, the default constructor must do all the initialising by itself!

Defining Laughter

Of course, if you want to be really lazy, the default constructor must do all the initialising by itself!

Defining Laughter

The final program

class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.println("haha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh();
		x.laugh();
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.println("haha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh();
		x.laugh();
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh();
		x.laugh();
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		*System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh();
		x.laugh();
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh();
		x.laugh();
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh();
		x.laugh();
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh();
		x.laugh();
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh();
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh();
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(String syl){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(String syl){
		System.out.print("ha");
		System.out.println("ha");
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	*public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher1 {
	public Laugher1(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher1 {
	public static void main(String args[]){
		Laugher1 x;
		x=new Laugher1();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher2 {
	public Laugher2(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher2 {
	public static void main(String args[]){
		Laugher2 x;
		x=new Laugher2();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher2 {
	public Laugher2(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher2 {
	public static void main(String args[]){
		Laugher2 x;
		x=new Laugher2();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher2 {
	public Laugher2(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher2 {
	public static void main(String args[]){
		Laugher2 x;
		x=new Laugher2();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3();
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}
	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
*		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print("ha");
		System.out.println("ha");
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print(default);
		System.out.println(default);
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print(default);
		System.out.println(default);
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print(default);
		System.out.println(default);
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher3 {
	public Laugher3(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print(default);
		System.out.println(default);
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher3 {
	public static void main(String args[]){
		Laugher3 x;
		x=new Laugher3("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher4 {
	public Laugher4(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print(default);
		System.out.println(default);
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher4 {
	public static void main(String args[]){
		Laugher4 x;
		x=new Laugher4("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher4 {
	*public Laugher4(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print(default);
		System.out.println(default);
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher4 {
	public static void main(String args[]){
		Laugher4 x;
		x=new Laugher4("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher4 {
	public Laugher4(){
		default="ha";
	}

	public Laugher4(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print(default);
		System.out.println(default);
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher4 {
	public static void main(String args[]){
		Laugher4 x;
		x=new Laugher4("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}
class Laugher4 {
	public Laugher4(){
		default="ha";
	}

	public Laugher4(String defaultSyl){
		default=defaultSyl;
		}

	public void laugh(){
		System.out.print(default);
		System.out.println(default);
		}

	public void laugh(String syl){
		System.out.print(syl);
		System.out.println(syl);
		}

	private String default;

	}

class UseLaugher4 {
	public static void main(String args[]){
		Laugher4 x;
		x=new Laugher4("Ho");
		x.laugh("HO")
		x.laugh("hee")
		}
	}