摘要:
父类的引用指向子类的对象(向上转型)的作用:良好的可扩展行(在给我们的软件增加一块功能或者删除一块功能的时候,应该不用修改程序的主体代码).也就是多态,实现代码的复用 (多态)public class Helloworld1 {public static void main(String args[]) {Cat cat = new Cat();cat.name = "tom";Dog dog = new Dog();dog.name = "jack";Person p = new Person();p.playWithAnimal(dog); //这里 阅读全文
posted @ 2012-07-17 23:28
建志
阅读(194)
评论(0)
推荐(0)
摘要:
父类的引用指向子类的对象,但是cat属于父类,所以Animal cat = new Cat()的cat对象,不能调用子类多出来的内容,比如这里的enjoy方法 (向上转型)public class Helloworld1 {public static void main(String args[]) {Animal cat = new Cat();cat.name = "tom";cat.sleep();}}class Animal {String name;public void sleep() {System.out.println(name+" is sle 阅读全文
posted @ 2012-07-17 23:27
建志
阅读(682)
评论(0)
推荐(0)
摘要:
所有的类都默认继承了Object类,但是如果是自己定义的类,建议重写里面的toString方法,不重写的话,打印的是类名+@+哈西码。String类自身重写了tostring(Object类)public class Helloworld1 {public static void main(String args[]) {Animal c = new Animal("jacky",20); System.out.println(c);}}class Animal {String name;int age = 10;public Animal(String name,int 阅读全文
posted @ 2012-07-17 23:22
建志
阅读(177)
评论(0)
推荐(0)
摘要:
1.super关键字,用于成员变量super.age 用于调用父类的方法super.d()public class Helloworld1 {public static void main(String args[]) {Cat c = new Cat("jacky",20);int m = c.m();System.out.println(m);}}class Animal {String name;int age = 10;public Animal(String name,int age) { this.name = name; this.age = age; } p 阅读全文
posted @ 2012-07-17 23:20
建志
阅读(104)
评论(0)
推荐(0)
摘要:
4.构造器还有一个作用,初始化成员变量public class Helloworld7 { public static void main(String args[]) { Person p1 = new Person("张三",19); Person p2 = new Person("李四",29); p1.m(p2); } } class Person { String name; int age; public Person(String name,int age) { this.name = name; this.age = age; } pub 阅读全文
posted @ 2012-07-17 23:17
建志
阅读(129)
评论(0)
推荐(0)
摘要:
public class Helloworld7 { public static void main(String args[]) { Person p1 = new Person("张三",19); Person p2 = new Person("李四",29); Hair h = new Hair("李四的一根头发"); p2.h = h; p1.m(p2.h); } } class Person { String name; int age; Hair h; public Person(String name,int age) 阅读全文
posted @ 2012-07-17 23:15
建志
阅读(82)
评论(0)
推荐(0)
摘要:
<html> <head> <title>注册页面表单</title> </head> <body> <form method="post" action=""> <table border="1" align="center" width="600" bgcolor="ffb7dd"> <tr align="center" bgcolor="# 阅读全文
posted @ 2012-07-17 23:13
建志
阅读(124)
评论(0)
推荐(0)
摘要:
条件查询:1.查询出工资大于1500的所有有雇员的信息select * from emp where sal>1500;2.查询每月可以拿到奖金的雇员的信息select * from emp where comm is not null;3.查询工资大于1500,并且可以拿到奖金的雇员的信息select * from emp where sal>1500 and comm is not null;4.查询工资不大于1500,并且不能拿到奖金的雇员的信息select * from emp where not(sal>1500 or comm is not null);5.查询基 阅读全文
posted @ 2012-07-17 23:02
建志
阅读(600)
评论(0)
推荐(0)
摘要:
//先创主表,再创从表 先删从表,再删主表//论坛用户表create table bbs_user(user_id integer primary key, //没有id的,给他创建一个iduser_name varchar2(15) not null,user_password number(12) not null,user_email varchar2(20) check (user_email like '%@%'), //检查约束,%代表任意长度字符串,_代表一个字符,用likeuser_birthday Date,user_sex varchar2(3) check 阅读全文
posted @ 2012-07-17 22:59
建志
阅读(131)
评论(0)
推荐(0)
浙公网安备 33010602011771号