1. A class is the basic constituent unit of a Java program, defines the properties and methods of an object, and is a collection of objects that have common properties and behaviors.
2. Nature of the object: attribute + behavior.
3. The basic structure of the class: Properties, methods, construction methods, inner classes, blocks. A property is a description of the data. The method is the behavior of the object. The constructor method is used to instantiate the object.
4. Method overloading:
1) Method Overloading principle: The function name is the same, the parameter type is different, the parameter number is different, the parameter order is different, in the same scope.
2) method overloads are not related to the return value type of the method, and only methods that have different return values do not form overloads.
5. Invocation of the method: Class name. method
6. Object creation: Suppose there is a class person, creating an object statement for Person p=new person ();
Here is an example of a reference to understanding
public class Cat {
public static void Main (string[] args) {
Kitty K1=new Kitty ();//Create an object K1
Kitty K2=new Kitty ("Kitty", 3);//Create an object K2, named Kitten, age 3
System.out.println ("Kitty's name:" +k1.name+k1.age+ "old");//Output Object K1 name and age
K1.play ();//Call the Play method
K1.eat ();//Call Eat method
System.out.println ("Kitty2 's name:" +k2.name+k2.age+ ");//Output Object K2 name and age
K2.play ();//Call the Play method
K2.eat ();//Call Eat method
}
}
Class kitty{
String name= "Kitten";
int age=1;
method of constructing without parameters
Kitty () {
}
A method of constructing parameters
Kitty (String Name,int age) {
This.name=name;
This.age=age;
}
How to Play
void Play () {
System.out.println ("Play dough");
}
How to Eat
void Eat () {
System.out.println ("Eat apples");
}
}
Understanding of the basic structure of Java classes