Java内部类(Inner Class)详解
简单的说,内部(inner)类指那些类定义代码被置于其它类定义中的类;而对于一般的、类定义代码不嵌套在其它类定义中的类,称为顶层(top-level)类。对于一个内部类,包含其定义代码的类称为它的外部(outer)类。
1 Static member class(静态成员类)
类声明中包含“static”关键字的内部类。如以下示例代码,
Inner1/Inner2/Inner3/Inner4就是Outer的四个静态成员类。静态成员类的使用方式与一般顶层类的使用方式基本相同。
public class Outer{
//just like static method, static member class has public/private/default access privilege levels
//access privilege level: public
public static class Inner1 {
public Inner1() {
//Static member inner class can access static method of outer class
staticMethod();
//Compile error: static member inner class can not access instance method of outer class
//instanceMethod();
}
}
//access privilege level: default
static class Inner2 {
}
//access privilege level: private
相关文档:
1.基本概念的理解
绝对路径:绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)例如:
C:\xyz\test.txt 代表了test.txt文件的绝对路径。http://www.sun.com/index.htm也代表了一个
URL绝对路径。
相对路径:相对与某个基准目录的路径。包含Web的相对路径(HTML中的相对目录),例如:在
......
1、 Java对象赋值
Java代码
Employee e1=
new
Employee(
"李"
);
//Employee是一个自定义类
Employee e2=e1; //赋值对象
e2.setName("王"
);
//改变对象e2的名字
System.out.println(e1.getName ......
JAVA中的传递都是值传递吗?有没有引用传递呢?
在回答这两个问题前,让我们首先来看一段代码:
Java代码
public class ParamTest {
// 初始值为0
protected int num = 0;
// 为方法参数重新赋值
public void change(int i) {
i = 5;
}
// 为方法参数重新赋值
public void change(ParamTest t) {
P ......
class TestTryFinallyC {
public static void main(String[] args) {
System.out.println(testt());
}
public static int testt() {
int x = 99;
try {
return x;
}finally {
x = 8;
}
}
}
某年某月的某一天, ......
java 保留2位小数 转载
方式一:
四舍五入
double f = 111231.5585;
BigDecimal b = new BigDecimal(f);
double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP). ......