-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDog.java
39 lines (32 loc) · 808 Bytes
/
Dog.java
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
32
33
34
35
36
37
38
39
public class Dog
{
private String name;
private int age;
//Let's create a constructor
public Dog(String name, int age){
//set the age and attributes to whatever we pass in
this.name=name;
this.age=age;
//The this keyword is referencing the attributes of the class
add2();
speak();
}
public void speak()
{
System.out.println("I am "+this.name+" and I am "+ this.age+ " years old");
}
//Lets create another method to get the age
public int getAge()
{
return this.age;
}
//Lets create another method that will set the age
public void setAge(int age)
{
this.age=age;
}
private int add2()
{
return this.age+2;
}
}