Creating objects in Java
Objects are a bundle of values. In Java, they can be created by instantiating classes using the new
keyword.
Here is a very basic Person
class:
public class Person {
private String name;
private String hobby;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
}
If we want to instantiate it, we’ll use the following:
Person p =...