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 界面直接或间接交互都会生成事 ......
Dojo 在基于Web 的应用程序中越来越受到欢迎。很多开发人员是 Java™ 编程方面的能手,但是在 JavaScript
方面却缺乏经验。从强类型、面向对象的编译语言转向动态的、弱类型脚本语言,开发人员需要经历概念跃迁带来的困难。这种混乱使开发人员很难正确地声明
Dojo 类。本文将帮助梳理这种混乱,解释为何必须 ......
1、set集合是最简单的一种集合,集合中不按指定的方式排序,并且没有重复对象。
2、set接口主要有两个实现类:HashSet和TreeSet
(1)HashSet:是按照哈希算法来进行存取集合中的对象,存取的速度比较快。
(2)TreeSet:实现了SortedSet接口,具有排序的功能。
3、HashSet类是按照哈希算法来存取 ......
package com.chinacache.utils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
public class FileUtils {
private static final Logger logger = Logger.getLogger(FileUtils.class);
/**
* 移动文件到指定目 ......