面向对象1

 1 public class Car {
 2 
 3         String name;
 4         
 5         int age;
 6         
 7         int goals=14;
 8         
 9         //行为.(方法)
10         //void,没有返回值。如果有返回值,要写明返回值的数据类型。如int jiayou()
11         void jinqiu(int goals1)  //括号内写参数
12         {
13             goals += goals1;  //运算式
14             System.out.println("本次进球数:"+goals1+"
"+"总进球数:"+goals);
15         }
}
 1 public class testcar {
 2 
 3     public static void main(String[] args) {
 4         // TODO 自动生成的方法存根
 5 
 6         Car c罗 = new Car();
 7         c罗.age=31;
 8         c罗.jinqiu(30);
 9         System.out.println("c罗的年龄是:"+c罗.age);
10         System.out.println("目前c罗进球数是:"+c罗.goals);
11         
12     }
13 
14 }

原文地址:https://www.cnblogs.com/hellodp/p/5134869.html