访问对象中的属性或方法

为对象的属性设置内容,同时调用tell()方法把内容输出

class Person{

         String name;

         int age;

         public void tell(){

                    System.out.println("姓名:"+name+",年龄:”+age);

         }

}

public class ClassDemo03{

        public static void main{String args[]{

                Person per=null;

                per.name="张三";

                per.age=30;

                per.tell();

          }

}

 

   

posted @ 2021-06-17 14:10  愿景在于做得多  阅读(39)  评论(0)    收藏  举报