/*
继承的练习
继承的特点:1、提高代码的复用性,
2、让类与类之间产生关系 给多态提供前提
java中只支持单继承,不直接支持继承多继承
单继承:即一个类智能有一个父类
*/
class ExtendsDemoTest
{
public static void main(String[] args)
{
ZiPerson zp=new ZiPerson();
zp.show();
System.out.println(zp.PI);
}
}
class Person
{
String name;
final static double PI=3.14;
//父类中的构造代码块也被子类继承了
{
System.out.println("父类中的构造代码块");
}
final void speak()
{
System.out.println("父类中的speak方法");
}
void show()
{
System.out.println("父类中的show方法");
}
}
class ZiPerson extends Person
{
int age;
void speak()
{
System.out.println("子类中的speak方法");
}
void show()
{
super.speak();
System.out.println("子类中的show方法");
}
}
继承的练习
继承的特点:1、提高代码的复用性,
2、让类与类之间产生关系 给多态提供前提
java中只支持单继承,不直接支持继承多继承
单继承:即一个类智能有一个父类
*/
class ExtendsDemoTest
{
public static void main(String[] args)
{
ZiPerson zp=new ZiPerson();
zp.show();
System.out.println(zp.PI);
}
}
class Person
{
String name;
final static double PI=3.14;
//父类中的构造代码块也被子类继承了
{
System.out.println("父类中的构造代码块");
}
final void speak()
{
System.out.println("父类中的speak方法");
}
void show()
{
System.out.println("父类中的show方法");
}
}
class ZiPerson extends Person
{
int age;
void speak()
{
System.out.println("子类中的speak方法");
}
void show()
{
super.speak();
System.out.println("子类中的show方法");
}
}