java 编程思想课后题(第五章)

练习1:

public class twoSum {
    public static void main(String[] args){
        class Test{
           String a;
        }
        Test a = new Test();
        System.out.println(a.a);
    }
}
练习2:

顺序不同,先静态初始块,然后初始块,最后构造方法。
练习3:

class printIn{
    printIn(){
        System.out.println("Hello World!");
    }
}
public class twoSum {
    public static void main(String[] args){
        printIn a = new printIn();
    }
}
练习4:

class printIn{
    printIn(){
        System.out.println("Hello World!");
    }
    printIn(String s){
        System.out.println(s + " Hello World!");
    }
}
public class twoSum {
    public static void main(String[] args){
        printIn a = new printIn();
        printIn b = new printIn("hehe");
    }
}

练习5:

class Dog{
    void bark(){
        System.out.println("barking");
    }
    void bark(String s){
        System.out.println("howling");
    }
}
public class twoSum {
    public static void main(String[] args){
        Dog xiaoMing = new Dog();
        xiaoMing.bark();
        xiaoMing.bark("aa");
    }
}
练习6:

class Dog{
    void bark(int a,String s){
        System.out.println("barking");
    }
    void bark(String s,int a){
        System.out.println("howling");
    }
}
public class twoSum {
    public static void main(String[] args){
        Dog xiaoMing = new Dog();
        xiaoMing.bark(1,"11");
        xiaoMing.bark("aa",1);
    }
}
练习7:
class Dog{

}
public class twoSum {
    public static void main(String[] args){
        Dog xiaoMing = new Dog();
    }
}

练习8:

class twoWay{
    void first(){
        System.out.println("this is the first way");
    }
    void second(){
        first();
        this.first();
    }
}
public class twoSum {
    public static void main(String[] args){
        twoWay a = new twoWay();
        a.second();
    }
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值