the use of Java object-oriented properties and methods Wang Coli (Star star)
//property method for carclasscar{//attribute format: Data type variable nameString color; String name; intWheelnumber; Public voidrun () {System.out.println ("Run the way the car starts up ~"); }}//methods of the main functionclassstar1{ Public Static voidMain (string[] args) {//object to create carCar Starcar =NewCar (); //Setting PropertiesStarcar.color = "Blue"; Starcar.name= "Rolls Royce Phantom"; Starcar.wheelnumber= 4; //call Car object to call car methodStarcar.run (); }}
Summary: (similar to OBJECT-C's syntax)
Object creation Syntax: The name of the class name object = new class name ();
The instance method is written in: public void method Name ( parameter ) {};
The object calls its own method inside the main function and sets its own properties ...
The use of Java object-oriented properties and methods (Small records in Java learning)