当前位置:首页 > 精品文档java面向对象习题
理解对象数组,创建Point数组。要求数组中的每个点都在与x, y 轴夹角为45度的直线上。
交换Point数组中任意两个元素的位置。 Public static void change(Point[] ps)
创建Circle数组。要求数组中的每一个圆的半径构成等差数列,差项为2,首项为1。每个圆的圆心(Point)都在与x, y 轴夹角为45度的直线上。
学习编写Bubble Sort
使用sort,排序数组后5个元素。
//查找元素
学习编写Stack。
学习编写循环Queue public class Queue{ public int[] arr = new int[5]; public int head = 0; public int count = 0; public boolean full(){ if(count == arr.length){ return true; }else{ return false; } } public boolean empty(){ if(count == 0){
}
return true; }else{ return false; } }
public boolean enQueue(int x){ if(count == arr.length){ return false; }else{ //{0, 0, 0, 0, 8} //count = 2; head = 3; arr[(head + count) % arr.length ] = x; count++; return true; } }
public int deQueue(){ int temp = arr[head % arr.length]; head++; count--; return temp; }
面向对象进阶
Java语言中,方法重载要求()。
A. 采用不同的参数列表 B. 采用不同的返回值类型
C. 调用时用类名或对象名做前缀 D. 在参数列表中使用的参数名不同
.阅读下面代码:
class TestSuper {TestSuper (int i) {System.out.println(\
class TestSub extends TestSuper { TestSub(){System.out.println(\class TestAll { public static void main (String [] args) { new TestSub (); } } 正确的是( )。
A. 编译出错.
B. 代码可正常运行,并打印出 TestSuper C. 代码可正常运行,并打印出 TestSub D. 代码在运行中将会出现Exception
写一棵产品继承树
Public void start(){System.out.println(“Office Start”);}
写一棵动物继承树
补充Teacher类
每个人都养了一条狗
每个学生,都有一个老师
为Circle类添加toString方法与equals方法
为产品继承树和动物继承树添加toString和equals方法
――――― class Super { public int getLenght () {return 4 ;} } public class Sub extends Super { public long getLenght () {return 5 ;} public static void main (String [] args) { Super sooper = new Super (); Sub sub = new Sub(); System.out.println (sooper.getLenght () + \ } }
共分享92篇相关文档