Java面向对象编程练习题(19)
发布时间:2021-06-08
发布时间:2021-06-08
int age;
public Person(String name,int age){ =name; this.age=age; }
public static void main(String[]args){ Person c=new Person("Peter",17); System.out.println(+" is "+c.age+" years old!"); } }
4、写出运行结果:
public class abc{
public static void main(String args[ ]) {
SubSubClass x = new SubSubClass(10 , 20 , 30); x.show(); } }
class SuperClass{
int a,b;
SuperClass(int aa , int bb){
a=aa; b=bb; }
void show( ){
System.out.println("a="+a+" b="+b); } }
class SubClass extends SuperClass{
int c;
SubClass(int aa,int bb,int cc){ super(aa,bb);
c=cc; } }
class SubSubClass extends SubClass{
int a;
SubSubClass(int aa,int bb,int cc){
super(aa,bb,cc); a=aa+bb+cc; }
void show(){
System.out.println("a="+a+" b="+b+" c="+c); } }