创建类

 1 class Person {
 2     public  int age = 19;   //成员属性
 3     public  String name = "张三";
 4    /* public  String sex;
 5     public void eat() {   // 成员方法
 6         System.out.println("吃饭啦");
 7     }
 8     public void sleep() {
 9         System.out.println("睡觉啦");
10     }*/
11    public void show() {
12        System.out.println("我叫"+name+", 我今年"+age+"岁");
13    }
14         }
15 public class test8 {
16     public static void main(String[] args) {
17         Person person = new Person();//通过new实例化对象
18 //        person.eat();//成员方法的调用是通过对象的引用来调用
19 //        person.sleep();
20         //产生对象    实例化对象
21         person.show();
22         Person person1 = new Person();
23         Person person2 = new Person();
24     }
25 }

 

posted @ 2020-05-09 14:56  听说在北郭  阅读(125)  评论(0)    收藏  举报