Java classes and objects, using programs to interpret

Source: Internet
Author: User

//First
1 Public classcardemo{2 Public Static voidMain (string[] args) {3Car Carwind =NewCar ("Red", "West");4Carwind.speed = 60;5Carwind.color = "Red";6Carwind.direction = "West";7 8System.out.println ("The speed of car" +carwind.speed);9SYSTEM.OUT.PRINTLN ("The color of car is" +carwind.color);TenSystem.out.println ("The direction of car is" +carwind.direction); One } A } - classcar{ - //define four member variables (attributes) the intSpeed ; - String color; - String name; - String direction; +}

A second

 Public classcardemo{ Public Static voidMain (string[] args) {Car carwind=NewCar ("Red", "West");//Create a reference to a car classCarwind.speed = 60; Carwind.color= "Red"; Carwind.direction= "West"; System.out.println ("The speed of car" +carwind.speed); System.out.println ("The color of car is" +Carwind.color); System.out.println ("The direction of car is" +carwind.direction);        Carwind.drivecar (); Carwind.speedup (5); System.out.println ("The speed of car" +carwind.speed); }}classcar{//define four member variables (attributes)    intSpeed ;    String color;    String name;        String direction; Car (intSpeed , string color, string direction) {         This. Speed =Speed ;  This. color =color;  This. Direction =direction; }         Public voidDrivecar () {System.out.println ("Here we go!"); }     Public voidSpeedupintaspeed) {         This. Speed = speed +Aspeed; }}

Java classes and objects, using programs to interpret

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.