java实验报告Object and Inheritance

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Report

Class:Q120101 Name:QianjunLiu No.:Q12010102

Course

Java

Programming

Language

Experi

ment

Name

Object and

Inheritance

Type

Verify Demo Integrated Design

Teacher Weimin Wu Score

1. Goal of this experiment

I.Know how to use Object, inheritance in Java;

ing Class, Object, Interface;

III.U sing tools to construct and implement Java applications.

2.Procedures

I. A program using Final, Abstract and Package.

●Step 1: type the following code and try to get to know the usage of

Final, Abstract and Package.

●Step 2: Summary the function of this program and learn the

relationship between class and object.

●Step 3:Please tell the function of each line.

II.A program using Interface.

●Step 1: type the following code and try to get to know the usage of

Interface.

●Step 2: Summary the function of this program and learn how to

use Interface.

●Step 3: Please tell the function of each line.

III. A program using Data and Time

Step 1: type the following code and try to understand Data and Time in Java.

●Step 2: Modify the source code to make it output different time

format. Such as:

Tue Sep 08 9:08:04 CST 2009 //toString

2009-9-8 9:08:04 //toLocalString

8 Sep 2009 01:08:04:GMT //toGMTString

●Step 3: Think about the time gap between two Dates or two Data

Times. How to calculate. And trying to modify the source code to make it reality( extends or Interface can be used).

A program using inheritance.

●Step 1: Analyze the following code and give the running

result:

IV.Make a program which can represent student. This class have the following property: studentID, classID, name, sex and age.

3.Recording of original data or result

(1)a programme of circle

Source code:

class CCircle

{

double pi;

double radius;

double getRadius(){

return radius;

}

void setCircle(double r, double p){

pi=p;

radius=r;

}

}

public class Ex2_1

{

public static void main(String args[]) {

CCircle cir1=new CCircle();

cir1.setCircle(2.0,3.1416);

System.out.println("radius="+cir1.getRadius());

}

}

(2)A program using Interface

Source code:

interface Sittable{

void sit();

}

interface Lie{

void sleep();

}

interface HealthCare{

void massage();

}

class Chair implements Sittable{

public void sit(){

System.out.println("It is sittable!");

};

}

class Sofa extends Chair implements Lie,HealthCare{ public void sleep(){

System.out.println("It is sleep!");

};

public void massage(){

System.out.println("give a message!");

};

public static void main(String[] args) {

相关文档
最新文档