package unit;
public class Base {
public Base ( ) {
System. out. println ( "Base" ) ;
}
}
class Child extends Base {
public Child ( ) {
System. out. println ( "Child" ) ;
}
}
public class Sample {
public static void main ( String[ ] args) {
Child c= new Child ( ) ;
}
}
Base
Child
进程已结束,退出代码为 0
package unit;
public abstract class Animal {
String color;
String weight;
int age;
}
package unit;
public class Bird extends Animal {
Bird ( String color, int age) {
super . color = color;
super . age = age;
}
public void printinfo ( ) {
System. out. println ( "我是一只" + color + "的鸟!" ) ;
System. out. println ( "今年" + age + "岁了!" ) ;
}
}
package unit;
public class Fish extends Animal {
Fish ( String weight, int age) {
super . weight = weight;
super . age = age;
}
public void printinfo ( ) {
System. out. println ( "我是一只" + weight + "重的鱼!" ) ;
System. out. println ( "今年" + age + "岁了!" ) ;
}
}
package unit;
public class Test {
public static void main ( String[ ] args) {
Bird bird = new Bird ( "红色" , 4 ) ;
Fish fish = new Fish ( "5斤" , 2 ) ;
bird. printinfo ( ) ;
fish. printinfo ( ) ;
}
}
我是一只红色的鸟!
今年4 岁了!
我是一只5 斤重的鱼!
今年2 岁了!
进程已结束,退出代码为 0
package unit2;
public abstract class Phones {
public abstract void call ( ) ;
}
package unit2;
public class APhone extends Phones {
public void call ( ) {
System. out. println ( "安卓手机打电话" ) ;
}
}
package unit2;
public class IPhone extends Phones {
public void call ( ) {
System. out. println ( "苹果手机打电话" ) ;
}
}
package unit2;
public class WPhone extends Phones {
public void call ( ) {
System. out. println ( "WPhone手机打电话" ) ;
}
}
package unit2;
public class TestCall {
public static void main ( String[ ] args) {
Phones aPhone= new APhone ( ) ;
aPhone. call ( ) ;
Phones iPhone= new IPhone ( ) ;
iPhone. call ( ) ;
Phones wPhone= new WPhone ( ) ;
wPhone. call ( ) ;
}
}
安卓手机打电话
苹果手机打电话
WPhone手机打电话
进程已结束,退出代码为 0