java 程序运行结果_阅读程序,写出运行结果

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

1、class Shape{

public void draw()   {     System.out.println(“draw Shape”);    }

}

class Circle extends Shape{

public void draw()   {     System.out.println(“draw Circle”);    }

}

class Rectangle extends Shape{

public void draw()   {     System.out.println(“draw Rectangle”);    }

}

public class ShapeTest{

public static void main(String[] args){

Shape[] shapes=new Shape[3];

Shape[0]=new Shape();

Shape[1]=new Circle();

Shape[2]=new Rectangle ();

for(int i=0;i

shapes[i].draw();

}

}

2、class Person{

private static int count=0;

String name;

public Person(String name)    {

this.name=name;

count++;

}

public void showData()    {

System.out.println("姓名:"+name);

System.out.println("人数:"+count);

}

}

public class BookConstructor{

public static void main(String args[])    {

Person one=new Person ("黄容");

one.showData();

Person two=new Person ("郭靖");

two.showData();

}

}

3、 try{

int a=1,b=0;

System.out.println(a/=b);

}catch(ArithmeticException e){

System.out.println(“捕捉到一个算术异常”);

}finally {

System.out.println("此行总被执行");

}

4、

public class student {

String name;

int age;

student()   {

this("default",20);

}

student(String a1,int a2)   {

name=a1;

age=a2;

}

public static void main(String args[]){

student s1=new student();

System.out.println("name="+s1.name+", age="+s1.age);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值