2月14日 Core Java 周三

继承
Animal
/* hao
* 2018-2-14 11:39:22
* 继承
*/
public class Animal {
int age;
String name;

void eat(){
    System.out.println("吃");
}

}
/* hao
* 2018-2-14 11:41:52
* Animal子类
*/
public class Dog extends Animal {

}

public class Initail {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Dog dog = new Dog();
    dog.age = 10;
    dog.name="xxx";
    dog.eat();
}

}
User
/* hao
* 2018-2-13 16:42:24
* User类
*/
public class User extends Object{
String name;
int code;
String type;
//创建无参方法
User(){
System.out.println(“父对象出生了”);
}

User(String name,int code,String type){
    this.name=name;
    this.code=code;
    this.type=type;
}

void speak(){
    System.out.println("爱说");
}
void eat(){
    System.out.println("爱吃");
}

void show(){
    System.out.println("展示自己信息");
}

}
/* hao
* 2018-2-14 21:32:35
* 子类
*/
public class Worker extends User {

// Worker(){
// super();
// System.out.println(“子对象出生了”);
// }

Worker(String name, int code, String type) {

// super(); // 显式调用
super(name, code, type); // 显式调用
}

public static void main(String [] args){
    Worker w = new Worker("aaa", 111, "222");
    w.speak();
    w.eat();
}

void speak(){
    System.out.println("能说");
}
void eat(){
    System.out.println("能吃");
}
void print(){
    System.out.println("Worker [name=" + name + ", code=" + code + ", type=" + type + "]");
}

}
/* hao
* 2018-2-14 21:27:57
* 测试
*/
public class TestUser {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Worker wo = new Worker("www",111,"ooo");
    Worker rk = new Worker("rrr",222,"kkk");
    wo.print();
    rk.print();
}

}

我宁愿失去一个印度,也不愿失去一个莎士比亚。
——丘吉尔《大国崛起大道思行》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值