-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectsCode.java
More file actions
31 lines (22 loc) · 861 Bytes
/
Copy pathObjectsCode.java
File metadata and controls
31 lines (22 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class HelloWorld
{
public static void main(String []args)
{
Dog myDog = new Dog(); // myDog isn't a primitive, its an instance of class Dog.
myDog.breed = "collie";
myDog.name = "Lassie";
myDog.age = 5;
myDog.bark();
System.out.println("My dog is a " + myDog.breed + " named " + myDog.name + " and is " +
myDog.age + " years old.");
Dog herDog = new Dog();
herDog.breed = "sheperd";
herDog.name = "Fido";
herDog.bark();
System.out.println("My dog is named " + myDog.name + " and her dog is named " + herDog.name);
Dog2 myDog2 = new Dog2("Lassie");
myDog2.setBreed("collie");
myDog2.bark();
System.out.println("My dog is named " + myDog2.getName());
}
}