Java笔记-面向对象(基础)习题八

Java笔记-面向对象(基础)习题八,第1张

Java笔记-面向对象(基础)习题八

public class Test {   //公有类
    int count = 9; //属性
    public void count1() { //Test类的成员方法
 			count=10;//这个count就是属性  改成 10
        	System.out.println("count1=" + count); //10  
    }
    public void count2() {  //Test类的成员方法
        System.out.println("count1=" + count++);
    } 
   
   	//这是Test类的main方法, 任何一个类,都可有main
    public static void main(String args[]) {
       //解读
       //1.  new Test()	是匿名对象, 匿名对象使用后,就不能使用
       //2.  new Test().count1() 创建好匿名对象后, 就调用count1()
       new Test().count1(); 
      
       Test t1= new Test();
       t1.count2();
       t1.count2();
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5716985.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存