packagecom.qf.code_09;//定义一个Code类classCode{//静态代码块static{int x =1000;System.out.println(x );}//无参构造方法publicCode(){System.out.println("code...");}//构造代码块:类的成员位置{int x =100;System.out.println(x);}//构造代码块{int y =200;System.out.println(y);}//有参构造方法publicCode(String name){System.out.println("code"+name);}//静态代码块static{int y =2000;System.out.println(y);}}//测试类publicclassCodeDemo{publicstaticvoidmain(String[] args){int x =10;System.out.println(x);//局部代码块{int y =20;System.out.println(y);}// System.out.println(y);System.out.println("----------------------------------------------");//通过无参构造方法创建Code类对象Code code =newCode();Code code2 =newCode("hello");}}
继承的特点:
1)在Java语言中,类和的类的关系是一种继承关系,这个继承只能支持"单继承",不支持多继承
class 父{}
class 父2{}
class 子 extends 父,父2{} 多继承:不支持
class 子 extends 父{} :正常的语法格式
2)类和类关系,虽然不支持多继承,但是层层单继承----> 多层继承