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应用的快速Web服务支持工具 - Netrifex
Proxisoft今天宣布Netrifex 1.0版。
Netrifex可以立即把Web Services添加到现有的Java SE和Java EE应用程序,从而实现把Web Services快速、低费用的部署到整个企业应用。
Netrifex增加Web Services到现有的Java应用中。该产品使用户能够:
* 快速创建Web Service ......
二 对象
类实例化可生成对象,对象通过消息传递来进行交互。消息传递即激活指定的某个对象的方法以改变其状态或让它产生一定的行为。一个对象的生命周期包括三个阶段:生成、使用和消除。
对象的清除
当不存在对一个对象的引用时,该对象成为一个无用对象。Java的垃圾 ......
oracle
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
String user="scott";
String password="tiger";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_S ......
今天重新整理电脑,找到一个文件,看了下日期(2006.11.3) ,怕不小心再丢了,存到网上来晒晒。
关键字又称保留字,是 Java 语言规定了特定含义的标识符。用户只能按照系统规定的方式使用,不能自行定义。关键字一律用小写字母表示。Java 中的关键字有 50 个,按用途划分为:数据类型、语句、修饰、方法、类、 ......
定义按值传递和按引用传递这两个术语是重要的。
按值传递意味着当将一个参数传递给一个函数时,函数接收的是参数的一个副本。因此,如 果函数修改了该参数,仅改变副本,而原始值保持不变。按引用传递意味着当将一个参数传递给一个函数时,函数接收的是参数的内存地址,而不是参数的副本。因 此,如果函数修改了该参数,调 ......