《java期末考的大题都在这》由会员分享,可在线阅读,更多相关《java期末考的大题都在这(14页珍藏版)》请在人人文库网上搜索。
1、1按要求编写一个Java应用程序:(1)定义一个接口CanFly,描述会飞的方法public void fly()。(2)分别定义类飞机和鸟,实现CanFly接口。(3)定义一个测试类,测试飞机和鸟,在main方法中创建飞机对象和鸟对象,再定义一个makeFly()方法,其中让会飞的事物飞。并在main方法中调用该方法,让飞机和鸟起飞。interface CanFly public void fly();class Plane implements CanFlypublic void fly() System.out.println(Plain-fly);class Bird implemen。
2、ts CanFlypublic void fly() System.out.println(Bird-fly);class FlyTest void makeFly(CanFly cf)cf.fly();public static void main(String args) Plane p = new Plane();Bird b = new Bird();FlyTest test = new FlyTest();test.makeFly(p);test.makeFly(b); 3.完数P184-2abstract class Numberabstract void method();cla。
3、ss Perfect extends Numbervoid method()System.out.println(2到1000的完数如下:);int i, j, sum;for(i=2;i);for(int j=0;j=startX & x=(startY-height) & y= startX) & (x =(startY - height);return rtn1 & rtn2;class PlainRectTest public static void main(String args) PlainRect rc = new PlainRect(10,10,20,10);System.o。
4、ut.println(rc. area();System.out.println(rc.perimeter();boolean flg = rc.isInside(25.5,13);if (flg)System.out.println(25.5,13)在矩形内.);else System.out.println(25.5,13)不在矩形内.);8. 编写一个类A,该类创建的对象可以调用方法f输出小写的英文字母表。然后再编写一个A类的子类B,要求子类B必须继承类A的方法f(不允许重写),子类B创建的对象不仅可以调用方法f输出小写的英文字母表,而且可以调用子类新增的方法g输出大写的英文字母表。最后。
5、编写主类C,在主类的main方法中测试类A与类B。class A void f()System.out.println(小写的英文字母表:);for(char c=a;c=1000|m=1000)MyException exception=new MyException(m,n);throw exception;if(m=o;j-)System.out.println(aj+”);14.等于0的项去掉public class ArrayTestpublic static void main(String args)int a=1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5;in。
6、t b=new inta.length;int index=0;for(int i=0;ib.length)len=b.length;int i;for(i=0;ilen;i+)bi=ai*bi;for(i=0;ib.length;i+)System.out.println(b+i+=+bi;16.Circle,具有属性半径/圆形class Circledouble radius;public circle(double radius)this.radius=radius;/面积public double getArea()return 3.14*radius*radius;/圆锥类class。
7、 ConeCircle bottom;double height;public Cone(circle bottom,double height)this.bottom=bottom;this.height=height;double getCubage()return1.0/3*bottom.get.Area()*height;class TestConepublic static void main(String args)Circle c=new Circle(3);Cone t=new Cone(c,2);System.out.println(“半径为”+c.radius+”圆锥的体积为”+t.getCubage(。