java第5天的代码
/*****************Animal.java begin ***********************/
public class Animal{
public void jj(){
}
public static void main(String args[]){
//编译时类型 //运行时类型
Animal animal=new Dog();//animal对象被声明为Animal类型,引用Dog对象
Dog dog=(Dog) new Animal();
Animal animal1=new Cat();
System.out.println(animal instanceof Animal );//true
System.out.println(animal instanceof Dog );//true
System.out.println(animal instanceof Cat );//false
Animal animal2=new Cat();//animal对象被声明为Animal类型,引用cat对象
System.out.println(animal1 instanceof Animal );
System.out.println(animal1 instanceof Dog );
System.out.println(animal1 instanceof Cat );
// Dog dog=new Dog();
System.out.println(dog instanceof Dog );//true
System.out.println(dog instanceof Animal );//true
System.out.println(dog instanceof Object );//true
//Dog类与Cat类之间没有直接或间接地继承关系
// System.out.println(Dog instanceof Cat);
}
}
class Dog extends Animal{
String name;
public void jj(String name){
}
}
class Cat extends Animal{
}
/*****************Animal.java end ***********************/
/*****************TestDuoTai.java begin ***********************/
public class TestDuoTai{
public static void main(String args[]){
//引用的是Cat1对象(调用有方法覆盖的方法)
Animal1 a=new Cat1();
a.show();
a.eat();
// a.a();
}
}
class Animal1{
public void a( ){}
public void eat(){
System.out.println("Animal1 eat...");
}
public void show(){
相关文档:
public static void main(String[] args)
{
InputStream is = CommonUtil.getStream("http://wz.csdn.net/");
String regex = "(?<=href=\")[^\"]*";//查找网页中所 ......
Java的优点有: 跨平台性很强的,一次编译到处运行,一边编译一边执行, 不受病毒的干扰。但是美中不足,运行速度比C,C++ 等语言慢, 访问硬件底层比不上C++,C,一些应用需求却需要执行纯 Java 程序无法完成的一些任务。为此SUN公司为了突破JAVA的瓶颈, 就引入了JNI 的作用, JNI就是能够兼容C,扬长避短, 快速的访问硬 ......
多态的目的
通过类型转换,把一个对象当作它的基类对象对待。
从相同的基类派生出来的多个派生类可被当作同一个类型对待,可对这些不同的类型进行同样的处理。
这些不同派生类的对象响应同一个方法时的行为是有所差别的,这正是这些相似的类之间彼此区别的不同之处。
动态绑定
将一个方法调用和一个方法主体连接到一起 ......
Oracle 存储过程返回结果集用 ref cursor 实现。
试验步骤如下:
1. 建立 ref cursor 类型和过程
CREATE OR REPLACE PACKAGE types
AS
TYPE ref_cursor IS REF CURSOR;
END;
/
CREATE TABLE STOCK_PRICES(
RIC VARCHAR(6) PRIMARY KEY,
PRICE NUMBER(7 ......