Java编程思想第6章习题答案

虽然网上有一些解法,但我分享一下我的解法,提供一下参考,简单一点感觉更好。
1、

package ch5;

public class Hello {
public Hello(){
	System.out.println("hello");
}
public static void main(String[] args) {
}
}

package ch6;
import ch5.Hello;
public class Pac {
public static void main(String[] args) {
	Hello hello=new Hello();
}

2、

package ch6;
import static net.mindview.util.Print.*;
import net.mindview.simple.*;
//import java.util.*;
public class Ve {
public static void main(String[] args) {
    Vector v=new Vector();
	print("i get");
}
}

3、

package ch6;
import static debug.Debug.*;
//import static debugoff.Debug.*;
public class UseDebug {
public static void main(String[] args) {
	debug(args);
}
}

4、

package ch6;

public class Example {
protected void print() {
	System.out.println("i was uesed");
}
}

package ch6;
public class UseExample {
public static void main(String[] args) {
	Example a=new Example();
	a.print();
}
}

5、
package ch6;

public class Example {
public int a=3;
private double b=4;
char c=‘5’;
protected void print() {
System.out.println(“i was uesed”);
}
}

package ch6;
public class UseExample {
public static void main(String[] args) {
Example a=new Example();
a.print();
System.out.println(a.a);
//System.out.println(a.b);
System.out.println(a.c);
}
}
6、
package ch6;
class Hi{
static protected int a=3;
void use(){
System.out.println(a);
}
}
public class Example {
public static void main(String[] args) {
Hi h=new Hi();
h.use();
}
}
7、
package ch6;
import access.*;
public class Example {
public static void main(String[] args) {
Widget w=new Widget();
}
}

package access;
public class Widget {

}
8、
package ch6;
//客户端程序员不能直接创建该对象意味着获取该对象的方法只能为包访问权限及以下以及该类的构造函数为private。
class Connection {
private Connection() {
System.out.println(“new Connection”);
}
static Connection get(){
return new Connection();
}
}
public class ConnectionManager {
static int time=3;
static Connection[] con=new Connection[3];//这里还没开始赋值,不会报错。
{
for(int i=0;i<3;i++) {
con[i]=Connection.get();
}
}
static Connection getConnection() {
if(time>0)
return con[–time];
else
System.out.println(“Null”);
return null;
}
public static void main(String[] args) {
ConnectionManager cm=new ConnectionManager();
for(int j=0;j<=3;j++) {
cm.getConnection();
}
}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

returnadsss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值