Learn to Program Java learning Object-oriented (ii) published, please visit by xuebiancheng8.com
The concepts of classes and objects, properties, and methods in object-oriented objects have been analyzed earlier. Let's learn how to define a class. For example, there is a student class, there are age, name and other attributes, there is a way to learn, eat.
The code is as follows:
public class person{
String name;
int age;
public void Study () {
System.out.println ("learning");
}
public void Eat () {
System.out.println ("being eaten");
}
}
The above defines a person class, the public class person
Public is open, class is a keyword, a class is defined, the person is the class name
String name;//defines the property name, which is a string
int age;//definition attribute age, type is int type
public void Study () {
System.out.println ("learning");
}
public void Eat () {
System.out.println ("being eaten");
}
The above respectively defines the study method and the Eat method, respectively printing is learning and is eating.
Please visit xuebiancheng8.com for details. URL is
Http://xuebiancheng8.com/play/goodgoodstudy_84_daydayup.html
Object-oriented learning of Java Tutorials (II.)