}
public Mytime getTime() { return time; }
public void setTime(Mytime time) { this.time = time; }
public Mydate getDate() { return date; }
public void setDate(Mydate date) {
this.date = date; }
public String toString() { return date+\的\+time; }
}
package timedate;
public class Text {
public static void main(String[] args) { Mytime a = new Mytime(22, 12, 35); Mydate b=new Mydate(2002,7,30);
FullTime c=new FullTime(b,a);
System.out.println(c.toString());
} }
5 package Student;
public class student { int num;
String name; double score;
student(int num, String name, double score) { this.num = num; }
public void A() {
this.name = name; this.score = score;
System.out.println(\学号:\ + num + \名字:\ + name + \成绩:
\ + score); } }
package Student;
public class text { }
public static void main(String[] args) { student a[]=new student[3]; a[0]=new student(01,\,94); a[1]=new student(02,\,98); a[2]=new student(03,\,99);
for (int j = 0; j < a.length; j++) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i].score < a[i + 1].score) { student b = a[i]; a[i] = a[i + 1]; a[i + 1] = b; }
} }
for(int i=0;i
二 选择题
1. B 2.B 3.B 4.CD 5.B 6.B 7.B 8.A 9.BD 10.C 程序分析题:
1 this super this super 2 public static void add(final int x2) {
x2++;
}
有final修饰的属性不能被第二次赋值。
3 用final修饰的类是不能被继承的类。 4 用final修饰的方法不能被重写。 三 编程题 1 package person;
public class Person { String name; int age;
double height;
Person(String name,int age,double height){ this.name=name; this.age=age;
this.height=height; }
public void sayHello(){
System.out.println(name+\); } }
package person;
public class Student extends Person { double score;
Student(String name, int age, double height, double score) { super(name, age, height); this.score = score; }
public void study() {
System.out.println(name + \的成绩是\ + score); }
public void sayHello() { super.sayHello(); }
}
package person;
public class Text {
public static void main(String[] args) {
Person a=new Person(\,23,1.53); a.sayHello();
Student b=new Student(\,23,1.53,90); b.sayHello(); b.study();
} }
2 package tuxing;
public abstract class Shape { double area; double per; String color; Shape(){}
Shape(String c){
color=c; }
public abstract void getArea(); public abstract void getPer(); public abstract void showAll(); public void getcolor(){
System.out.println(color); } }
public class Rectangle extends Shape{ double width;
double height; Rectangle(){}
Rectangle(double w,double h,String color){
super(color); width=w;
height=h; }
public void getArea(){
System.out.println(\矩形的面积:\+width*height); }
public void getPer(){
System.out.println(\矩形的周长:\+2*(width+height)); }
public void showAll(){
this.getArea(); this.getPer();
System.out.println(\矩形的颜色:\+color);
}
}
public class Circle extends Shape{ double radius;
Circle(){}
Circle(double r,String color){ }
public void getArea(){
System.out.println(\圆的面积:\+Math.PI*radius*radius); }
public void getPer(){
System.out.println(\圆的周长:\+2*Math.PI*radius); }
public void showAll(){ this.getArea(); this.getPer();
System.out.println(\圆的颜色:\+color); }
super(color); radius=r;
}
public class PolyDemo {
public static void main(String[] args) { }
Rectangle a=new Rectangle(2,3,\); a.showAll();
Circle b=new Circle(3,\); b.showAll(); }
3 package qiche;
public class Vehicle { private String brand; private String color; private double speed=0;
Vehicle(String b,String c,double s){ brand=b; color=c; speed=s; }
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库一有关java的第四次题(5)在线全文阅读。
相关推荐: