Initial knowledge of Java class

Source: Internet
Author: User

/*
* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.