02 - Class and Object-MJS
02 - Class and Object-MJS
int size;
String breed;
String name;
void bark(){
System.out.println(“Wof! Wof!”);
}
Write tester/driver class
class DogTest {
public static void main (String[] args){
// test will be in here
}
}
Write test
class DogTest {
public static void main (String[] args){
Dog d = new Dog(); // make object (term: instantiate)
myBaby.name = “Sarah”;
…
Two use of main
Test your real test
–It is possible to have main in each
class to test class itself
To launch/start your java Apps
–main is entry point
Class is not object
One class, many objects
If you want to move around the room and still control the
television, you take the remote/reference with you, not the
television.
Reference as remote
Example
Dog myDog = new Dog();
3 Steps Object creation