Java: class , objects
Java: class , objects
1 Inheritance(继承)的关键字extends
class MountainBike extends Bicycle {
}
但是不能多重继承。不过可以通过implements多个interface来实现类似的东西
2 interface
interface Bicycle {
void changeCadence(int newValue); // wheel revolutions per minute
void changeGear(int newValue);
void speedUp(int increment);
void applyBrakes(int decrement);
}
class ACMEBicycle implements Bicycle {
// remainder of this class implemented as before
}
可实现(implements)多个interface
class MyClass extends MySuperClass implements YourInterface {
//field, constructor, and method declarations
}
means that MyClass is a subclass of MySuperClass and that it implements the YourInterface interface
3 package
A package is a namespace that organizes a set of related classes and interfaces.
4 Access Modifier
public, private, protected
public class Bicycle {
private int cadence;
public int aag;
public void test();
}
每个field或method都必须单独修饰
Access Levels
ModifierClassPackageSubclassWorld
public
Y
Y
Y
Y
protected
Y
Y
Y
N
no modifier
Y
Y
N
N
private
Y
N
N
N
约定:
class 名字的第一个字母大写; method第一个word是动词
5 Constructors
The compiler automatically provides a no-argument, default constructor for any class without constructors.
This default constructor will call the no-argument constructor of the superclass.
6 method & parameter
The Java programming language doesn't let you pass methods into methods. But you can pass an object into a method and then invoke the object's methods.
can Returning a Class or Interface??
7 this : current object
public class Point {
public int x = 0; //field可以这样初始化
public int y = 0;
相关文档:
Java 最新的事件处理方法是基于授权事件模型
事件源生成事件并将其发送至一个或多个监听器
监听器简单地等待,直到它收到一个事件。一旦事件被接受,监听器将处理这些事件,然后返回。
事件:在授权事件模型中,事件是一个描述事件源状态改变的对象 。
通过鼠标、键盘与 GUI 界面直接或间接交互都会生成事 ......
线性表,链表,哈希表是常用的数据结构,在进行Java开发时,JDK已经为我们提供了一系列相应的类来实现基本的数据结构。这些类均在java.util包中。本文试图通过简单的描述,向读者阐述各个类的作用以及如何正确使用这些类。
Collection
├List
│├ ......
当JVM(Java虚拟机)启动时,会形成由三个类加载器组成的初始类加载器层次结构:
bootstrap classloader
|
extension classloader
&n ......
public List<Integer> findSame(int array1[], int array2[]) {
// 重复元素结果集合
List<Integer> result = new ArrayList<Integer>();
// ......
定义按值传递和按引用传递这两个术语是重要的。
按值传递意味着当将一个参数传递给一个函数时,函数接收的是参数的一个副本。因此,如 果函数修改了该参数,仅改变副本,而原始值保持不变。按引用传递意味着当将一个参数传递给一个函数时,函数接收的是参数的内存地址,而不是参数的副本。因 此,如果函数修改了该参数,调 ......