JAVA运算符

来源:互联网 发布:百度数据分析工具 编辑:程序博客网 时间:2024/04/23 23:25

1. 类的句柄是可以被覆盖的

class Number {
int i;
}

Number n1 = new Number();
Number n2 = new Number();
n1 = n2;
这个之后,n1原来的句柄已经丢失,句柄变成和n2是一样的。

2.  几个特性

Public:对所有类可见

Protected:对同一包中的类,和子类可见

Private:仅对类本身可见        

Default:对同一包中的类可见

3. 构建器

全都会在构建器进入或者发生其他任何事情之前得到初始化

例如:

//: OrderOfInitialization.java
// Demonstrates initialization order.
// When the constructor is called, to create a
// Tag object, you'll see a message:
class Tag {
Tag(int marker) {
System.out.println("Tag(" + marker + ")");
}
}
class Card {
Tag t1 = new Tag(1); // Before constructor
Card() {
// Indicate we're in the constructor:
System.out.println("Card()");
t3 = new Tag(33); // Re-initialize t3
}
Tag t2 = new Tag(2); // After constructor
void f() {
System.out.println("f()");
}
Tag t3 = new Tag(3); // At end
}
public class OrderOfInitialization {
public static void main(String[] args) {
Card t = new Card();
t.f(); // Shows that construction is done
}

} ///:~
结果:
Tag(1)
Tag(2)
Tag(3)
Card()
Tag(33)
f()


4. static 初始化只有在必要的时候才会进行。

“过载”是指同一样东西在不同的地方具有多种含义;

而“覆盖”是指它随时随地都只有一种含义,只是原先的含义完全被后来的含义取代了。

“抽象方法”。它属于一种不完整的方法,只含有一个声明,没有方法主体。下面是抽象方法声明时采用的语法
abstract void X();
包含了抽象方法的一个类叫作“抽象类”。如果一个类里包含了一个或多个抽象方法,类就必须指定成bstract(抽象)。否则,编译器会向我们报告一条出错消息。
5. 接口
“ interface”(接口)关键字使抽象的概念更深入了一层。我们可将其想象为一个“纯”抽象类。它允许创
建者规定一个类的基本形式:方法名、自变量列表以及返回类型,但不规定方法主体。接口也包含了基本数
据类型的数据成员,但它们都默认为 static 和 final。

为了生成与一个特定的接口(或一组接口)相符的类,要使用 implements(实现)关键字。


0 0