如题
一个一个重载的方法好像太麻烦,有没有简单点的办法啊?
一个一个重载的方法好像太麻烦,有没有简单点的办法啊?
解决方案 »
- java
- 关于线性表中出入的问题
- java awt 画不规则封闭多边形的问题
- Hibernate在什么情况下会给类建立关系(For example:one-to-many,many-to-one Etc.),难道仅仅是为了省代码?
- 问下下拉式菜单怎么和数据库连起来啊?
- 请教,domain object model是怎样一个东西
- 使用FileReader类、LineNumberReader类是否只能抛出IOException,不能抛出自定义类,请详细解释!
- 在eclipse 字体问题
- 如何不利用IDE,而利用jar包对java源文件进行编译
- 制作图形统计图
- 一个有关snmp4j开源包的问题!!!急!!!小女子先谢过了!!!!在线等待
- 【急】applet 传对象 到servlet 所遇到的问题
public class E06_AccessControl {
public int a;
private int b;
protected int c;
int d; // "Friendly"
public void f1() {}
private void f2() {}
protected void f3() {}
void f4() {} // "Friendly"
public static void main(String args[]) {
E06_AccessControl test =
new E06_AccessControl();
test.a = 1;
test.b = 2;
test.c = 3;
test.d = 4;
test.f1();
test.f2();
test.f3();
test.f4();
}
} ///:~
You can see that main( ) has access to everything because it’s a member. If you create a separate class within the same package, that class cannot access the private members:package c05;
public class E06_Other {
public E06_Other() {
E06_AccessControl test =
new E06_AccessControl();
test.a = 1;
//! test.b = 2; // Can't access: private
test.c = 3;
test.d = 4;
test.f1();
test.f3();
test.f4();
}
} ///:~
If you create a class in a separate package (which you can do either by explicitly giving a package statement, or by simply putting it in a different directory) then it is unable to access anything but public members:
//: c05:other2:E06_Other2.java
// A separate class in the same package cannot
// access private elements:
package c05.other2;
public class E06_Other2 {
public E06_Other2() {
c05.E06_AccessControl test =
new c05.E06_AccessControl();
test.a = 1;
test.f1();
}
} ///:~