0.3 class is created and references

Recently a little lazy, feel some basic statements and the format is not necessary to write, so this update is to create classes and references, direct po bar code, this simple point

------------------------------------------------------------------------------------------------------------------------------------------------------------

SxtStu class {public

// attribute Fields
int the above mentioned id;
String sname;
int Age;

Computer CoMP; // computer

// method
void Study () {
System.out.println ( "I'm seriously study !!, use a computer:" + comp.brand);
}

void Play () {
System.out.println () "I am playing a game tomorrow Ark!!";
}

// constructor. Used to create objects of this class. No-argument constructor can be created automatically by the system.
SxtStu () {
System.out.println ( "call the constructor with no arguments!");
}

// entry program execution must be
// Sxtstu.java the javac, Java Sxtstu
public static void main (String [] args) {
SxtStu new new SxtStu STU = (); // Create an object
stu.id = 1001;
stu.sname = "LPY";
stu.age =. 19;

Computer Computer new new = C1 ();
c1.brand = "the HP ";

stu.comp = c1;

stu.play();
stu.study();

}
}

class Computer {
String brand;
}

Guess you like

Origin www.cnblogs.com/shit-mountain-filter/p/11240766.html