物件導向練習題答案

2021-08-30 19:39:35 字數 1100 閱讀 3811

答案整理如下:

一、類和物件

1.定義乙個類demo,其中定義乙個求兩個資料和的方法,定義乙個測試了test,進行測試。

class demo

public int add()

}class test

}

2.定義乙個長方形類,定義 求周長和面積的方法,然後定義乙個測試了test2,進行測試。

class rectangle

public int getarea()

public rectangle(){}

public rectangle(int length,int width)

}class test2

}

3.定義乙個員工類,自己分析出幾個成員,然後給出成員變數,構造方法, get***()/set***()方法,以及乙個顯示所有成員資訊的方法。並測試。

class employee

public void setname(string name)

public int getage()

public void setage(int age)

public int getid()

public void setid(int id)

public employee(string name, int age, int id)

public employee(){}

}class test3

}

4.定義乙個類mymath,提供基本的加減乘除功能,然後進行測試。

class mymath

public int add()

public int sub()

public int mul()

public int div()

}

5.定義一類圓,求圓的周長和面積

class circle

public double getarea()

}

物件導向練習題

一 讀程式 1 寫出下列 的執行結果 class fatherclass public class test extends fatherclass public static void main string args 結果 fatherclass create fatherclass creat...

物件導向練習題

class myyear object definit self self.year int input 請輸入年份 def show season self for i in range 1,13 if i in 12,1,2 print i,冬季 elif i in 3,4,5 print i,...

物件導向 練習題1

package com.lrq import org.omg.portableserver.threadpolicyoperations author 李瑞琦 1.請定義乙個交通工具 vehicle 的類 其中有 屬性 速度 speed 體積 size 等,方法 移動 move 設定速度 setsp...