Created
August 13, 2017 06:30
-
-
Save wookay/bc9d3e2f7643f6ebea843ef22a48d2fc to your computer and use it in GitHub Desktop.
oop dogs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Dog | |
{ | |
//Instance vars | |
private String name; | |
private Int age; | |
//constructor | |
public Dog(String initName) | |
{ | |
name = initName; | |
age = 0; | |
} | |
//methods | |
public String getName() | |
{ | |
return name; | |
} | |
public void setName() | |
{ | |
return name; | |
} | |
public int getAge() | |
{ | |
return age; | |
} | |
public void addAYear() | |
{ | |
age = age + 1; | |
} | |
public void setAge() | |
{ | |
return age; | |
} | |
public String getData() | |
{ | |
String data = ""; | |
data = name; | |
data = data + "\n\tAge: " + age; | |
return data; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutable struct Dog | |
name::String | |
age::Int | |
Dog(name::String) = new(name, 0) | |
end | |
function addAYear(dog::Dog) | |
dog.age += 1 | |
end | |
function getData(dog::Dog) | |
string("Name: ", dog.name, "\n", "Age: ", dog.age) | |
end | |
dog = Dog("댕댕이") | |
println(getData(dog)) | |
addAYear(dog) | |
println(getData(dog)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment