★ anatomy of a java class

creating & designing a class, instance variables, methods, object-oriented design

warm-up

public void doggy (String a, String b){
	Srtring output = "Doggy!";

	for (int i = 0; i < b.length(); i++){
		String aLetter = a.substring(a.length()-1 - i, a.length() - i);
		String bLetter = b.substring(i, i+1);

		if (aLetter.equals(bLetter)){
			output = "Good " + output;
		}else if ((bLetter + aLetter).equals("no")){
			output = "Bad " + output;
		}
	}
	System.out.println(output);
}

what is printed when running the following…?

doggy(”coding”, “gnome”);

A) Bad Doggy!

B) Good Doggy!

C) Good Good Doggy!

D) Doggy!

E) Bad Bad Doggy!

notes

class in java is a blueprint for creating objects

most classes will have the keyword public (but not required)

the next thing we define in a class is usually in its constructors

methods define the behaviors of the objects

<aside> ⁉️ remember: instance variables = attributes, fields, properties

</aside>

instance variables should be declared private