Professional Documents
Culture Documents
01b Classes, Objects, and Methods (Review)
01b Classes, Objects, and Methods (Review)
01b Classes, Objects, and Methods (Review)
//constructor method
public Person(String n, int a) {
name = n;
age = a;
}
Every object will have all the fields and methods in the
class, but each object will have it's own values.
//default constructor
public Coin() {
name = "";
value = 0;
}
//parameterized constructor
public Coin(String n, int v) {
name = n;
value = v;
}
}
DEFAULT constructor
PARAMETERIZED constructor
Writing methods
This method has int as the return type. A method can return
any valid type (primitives like int, double, etc., or reference
types like String, Person, etc.).
The void return type
The void return type is commonly misunderstood. A method
that returns void does not return any type of data back to
where it was called.
It does, however, run its code block, then return back to where
it was called.