对象内存图

 1 public class Student {
 2     String name;
 3     int age;
 4     public void eat(){
 5         System.out.println("吃饭");
 6     }
 7     public void study(String subject){
 8         System.out.println("我要学习"+subject);
 9     }
10 }
11 public class DemoStudent {
12     public static void main(String[] args) {
13         Student s=new Student();
14         s.name="JayChou";
15         s.age=18;
16         System.out.println(s.name+" "+s.age);
17         s.eat();
18         s.study("数学");
19     }
20 }
21 =======================
22 JayChou 18
23 吃饭
24 我要学习数学

以上为2个Java源文件,否则会编译错误(一个源文件至多有一个public类)

第一次画图,哈哈!!!

栈(先进后出)

猜你喜欢

转载自www.cnblogs.com/XiaoJin0/p/10544951.html
今日推荐