/*
* class defines the characteristics and behavior of an object, and the member variables and methods of objects that share common characteristics
* object is an instance of a class
*/
A class defines the common properties and behavior of an object
We use variables to represent properties, to represent behaviors in methods
public class student{
A variable represents a property of a class member, and a variable must declare a type
String name;
String Rollno;
int age;
char gender;
Eight types of variables in Java
1. Integer type byte (1), short (2), int (4), Long (8)
2. Float type float (4), double (8)
3. Boolean type Boolean (1)
4. String type char (2)
Defining member methods within a class
The data type method name (parameter list) returned by the Access delimiter {method contents}
public void Takeexam () {
System.out.println ("I passed the exam!") ");
}
public void Taoke () {
System.ou.println ("I can skip classes occasionally.") ");
}
public void Palygame () {
Span style= "font-size:18px" > System.out.println ("Skipping class is not about playing games!") ");
}
Define an entry to run the program, which is the main method, the Main method
public static void Main (string[] args) {
Instantiate a student object and let him take the exam
Student Xiaoma = new Student (); Instantiation of an object
xiaoma.rollno= "20150104202";
Xiaoma.name= "Mario";
Xiaoma.age= "18";
Xiaoma.takeexam;
}
}
Initial knowledge of Java class