类的封装与继承习题(题)
更新时间:2023-05-04 09:31:01 阅读量: 实用文档 文档下载
- 对象推荐度:
- 相关推荐
. . .
1.以下关于继承的叙述正确的是( C )。
A、在Java中类只允许单一继承
B、在Java中一个类只能实现一个接口
C、在Java中一个类不能同时继承一个类和实现一个接口
D、在Java中接口只允许单一继承
2.有继承关系时用到的关键字是(A )。( 2 分)
A:extend
B:extends
C:implements
D:implement
3:Java变量中,以下不属于复合类型的数据类型是( D)。( 2 分)
A:类
B:字符型
C:数组型
D:接口
4:java中定义数组名为 abc,下面(B )可以得到数组元素的个数。( 2 分) A:abc.length( )
B:abc.length
C:len(abc)
D:ubound(abc)
5:下列说确的是(A )。( 2 分)
A:编译后的Java源程序根据文件中定义的类和接口的个数产生相应个数的.class字节码文件。
B:Java语言的源文件中不是任何地方都可以加注释的。
C:一个文件中可以有多个访问权限为public的类。
D:含有main()方法的类可以为public的类,也可以为其他类。
6:在调用构造函数时(C )( 2 分)
A:子类可以不加定义就使用父类的所有构造函数
B:不管类中是否定义了何种构造函数,创建对象时都可以使用默认构造函数C:先调用父类的构造函数
D:先调用形参多的构造函数
7:Java与C/C++比较说法错误的是(D)。( 2 分)
A:Java不提供goto语句,所以也就没指定goto作为关键字。
.. ..
. . .
B:Java没有指针。
C:Java没有联合和结构
D:Java只有单继承没有多重继承。
8:若需要定义一个类域或类方法,应使用( B)修饰符。( 2 分)
A:static
B:package
C:private
D:public
9:下列说法( C)是正确的。( 2 分)
A:程序执行到break语句是一定会结束所有的循环
B:程序执行到continue语句时会结束当前循环
C:break语句和continue语句都可以和标签协同使用
D:continue语句和break语句的作用相同
10:以下说确的是(D )。( 2 分)
A:每个Java类都至少有一个构造方法,如果没有则机器自动生成一个默认的构造方法。
B:如果类里定义了一个或多个构造方法,那么java也提供默认的构造方法
C:每个Java类中用户必须定义至少一个构造方法。
D:以上都不对
11:对封装的理解正确的是(A )。( 3 分)
A:封装就是把对象的属性和行为结合成一个独立的单位。
B:封装就是把对象完全隐蔽起来,不让外界访问。
C:封装性是一个使用问题。
D:封装和抽象是一回事。
12:对成员的访问控制保护最强的是(C )。( 3 分)
A:public
B:缺省
C:private
D:protected
.. ..
. . .
13:类Test1定义如下:
1.public class Test1{
2. public float aMethod(float a,float b){ }
3.
4.} 将以下( B)方法插入行3是不合法的。( 3 分)
A:public float aMethod(float a, float b,float c){ }
B:public float aMethod(float c,float d){ }
C:public int aMethod(int a, int b){ }
D:private float aMethod(int a,int b,int c){ }
14关于构造函数的说法( B)正确。( 2 分)
A:一个类只能有一个构造函数
B:一个类可以有多个不同名的构造函数
C:构造函数与类同名
D:构造函数必须自己定义,不能使用父类的构造函数
15:关于以下程序段,正确的说法是(D )。
1.String s1=”abc”+”def”; 2. String s2=new String(s1); 3. if (s1= =s2)4.System.out.println(“= = succeeded”); 5.if (s1.equals(s2)) 6.System.out.println(“.equals() succeeded”);( 2 分) A:程序将输出:= = succeeded
B:程序将输出: .equals() succeeded
C:程序将输出:= = succeeded .equals() succeeded
D:程序无输出
16:关于以下程序代码的说明正确的是( C)。
1.class HasStatic{ 2. private static int x=100; 3. public static void main(String args[ ]){ 4. HasStatic hs1=new HasStatic( ); 5. hs1.x++; 6. HasStatic hs2=new HasStatic( ); 7. hs2.x++; 8. hs1=new HasStatic( ); 9. hs1.x++; 10. HasStatic.x- -; 11.System.out.println(“x=”+x); 12. } 13. }( 2 分)
A:5行不能通过编译,因为引用了私有静态变量
B:10行不能通过编译,因为x是私有静态变量
C:程序通过编译,输出结果为:x=103
D:程序通过编译,输出结果为:x=102
.. ..
. . .
三、程序阅读题
1、以下程序的输出结果为___ Peter is 17 years old!___________________。
public class Person {
String name;
int age;
public Person(String name, int age) {
b543b0fc4531b90d6c85ec3a87c24028905f8517 = name;
this.age = age;
}
public static void main(String[] args) {
Person c = new Person("Peter", 17);
System.out.println(b543b0fc4531b90d6c85ec3a87c24028905f8517 + " is " + c.age + " years old!");
}
}
2、以下程序的输出结果为__课程号:101 __课程名:ASP __学分:_3_________________。public class Course {
private String cNumber;
private String cName;
private int cUnit;
public Course(String number, String name, int unit) {
cNumber = number;
cName = name;
cUnit = unit;
}
public void printCourseInfo() {
System.out.println("课程号:" + cNumber + " 课程名:" + cName + " 学分:" + cUnit);
}
}
class CourseTest {
public static void main(String[] args) {
Course c;
c = new Course("101", "ASP", 3);
c.printCourseInfo();
}
}
.. ..
. . .
3、以下程序的输出结果为_汤姆猫_体重:20斤_____________________。
public class Tom {
private float weight;
private static String name;
public void setWeight(float weight) {
this.weight = weight;
}
private void out() {
System.out.println(name + "体重:" + weight + "斤");
}
public static void main(String[] args) {
b543b0fc4531b90d6c85ec3a87c24028905f8517 = "汤姆猫";
Tom cat = new Tom();
cat.setWeight(20);
cat.out();
}
}
4、以下程序的输出结果::Tom 年龄:15家庭住址: 金水区学校:九中 : 66123456 public class Father {
String name, address, tel;
int age;
public Father(String name, int age) {
b543b0fc4531b90d6c85ec3a87c24028905f8517 = name;
this.age = age;
}
void out() {
System.out.print(":" + name);
System.out.print(" 年龄:" + age);
}
void outOther() {
System.out.print(" 家庭住址:" + address);
System.out.print(" :" + tel);
}
}
.. ..
. . .
class Son extends Father {
String school;
public Son(String name, int age) {
super(name, age);
}
void out() {
super.out();
super.outOther();
System.out.println(" 学校:" + school);
}
public static void main(String args[]) {
Son son = new Son("Tom", 15);
son.address = "金水区";
son.school = "九中";
son.tel = "66123456";
son.out();
}
}
5、下列程序的运行结果是__12345___________________。public class MyClass {
int a[] = { 1, 2, 3, 4, 5 };
void out() {
for (int j = 0; j < a.length; j++)
System.out.print(a[j] + "");
}
public static void main(String[] args) {
MyClass my = new MyClass();
my.out();
}
}
1、import java.io.*;
public class abc
{
public static void main(String args [ ])
{
.. ..
. . .
AB s = new AB("Hello!","I love JAVA.");
System.out.println(s.toString( ));
}
}
class AB {
String s1;
String s2;
public AB(String str1, String str2)
{
s1 = str1;
s2 = str2;
}
public String toString( )
{
return s1+s2;
}
}
运行结果:____ Hello! I love JAVA.________________
2、 import java.io.* ;
public class abc
{
public static void main(String args[ ])
{ int i, s = 0 ;
int a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 }; for ( i = 0 ; i < a.length ; i ++ )
if ( a[i]%3 = = 0 ) s += a[i] ;
System.out.println("s="+s);
}
}
运行结果:__s=180__________________
3、import java.io.* ;
public class abc
.. ..
. . .
{
public static void main(String args[ ])
{
System.out.println("a="+a+"\nb="+b);
}
}
class SubClass extends SuperClass
{ int c;
SubClass(int aa, int bb, int cc)
{
super(aa, bb);
c=cc;
}
}
class SubSubClass extends SubClass
{ int a;
SubSubClass(int aa, int bb, int cc)
{ super(aa, bb, cc);
A = aa+bb+cc;
}
void show()
{
System.out.println("a="+a+"\nb="+b+"\nc="+c);
}
}
运行结果:a=60
b=20
c=30
1.以下程序的输出结果为相等____________________ 。
class StringTest1
{
public static void main(String[] args)
{
String s1="hello";
.. ..
. . .
String s2=new String("hello");
if(s1.equals(s2)){
System.out.println("相等");
}else{
System.out.println("不相等");
}
}
}
2.以下程序段的输出结果为 56789 ____________________ 。
public class TestArray
{
public static void main(String args[ ]){
int i , j ;
int a[ ] = { 5,9,6,8,7};
for ( i = 0 ; i < a.length-1; i ++ ) {
int k = i;
for ( j = i ; j < a.length ; j++ )
if ( a[j]
int temp =a[i];
a[i] = a[k];
a[k] = temp;
}
for ( i =0 ; i
System.out.print(a[i]+" ");
System.out.println( );
}
}
3.写出以下程序的功能。
import java.io.*;
public class TestFile
{
public static void main(String args[]) throws Exception .. ..
. . .
{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new FileWriter(“input.txt"));
String s;
while (true)
{
System.out.print("请输入一个字符串: ");
System.out.flush();
s=br.readLine();
if (s.length()==0) break;
bw.write(s);
bw.newLine();
}
bw.close();
}
}
功能:判断输入字符串是否等于input.txt文件中的字符串
4.阅读以下程序,写出输出结果。
class Animal {
Animal() {
System.out.print ("Animal "); }
}
public class Dog extends Animal {
Dog() {
System.out.print ("Dog "); }
public static void main(String[] args) {
Dog snoppy= new Dog(); }
}
输出结果:_ Animal ___ Dog ________________
.. ..
. . .
五、程序设计题
1、按以下要求编写程序
(1) 创建一个Rectangle类,添加width和height两个成员变量
(2) 在Rectangle中添加两种方法分别计算矩形的周长和面积
(3) 编程利用Rectangle输出一个矩形的周长和面积
解答:package training5;
//(1) 创建一个Rectangle类,添加width和height两个成员变量
//(2) 在Rectangle中添加两种方法分别计算矩形的周长和面积
//(3) 编程利用Rectangle输出一个矩形的周长和面积
public class Rectangle {
private int width;
private int height;
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
}
public void square(){
int square;
square=width*height;
System.out.println("面积:"+square);
}
public void zhouc(){
int zhouc;
zhouc=2*(width+height);
System.out.println("周长;"+zhouc);
}
public static void main(String args[]){
Rectangle jux=new Rectangle(3,5);
jux.square();
jux.zhouc();
}
}
.. ..
正在阅读:
类的封装与继承习题(题)05-04
危重孕产妇救治中心基本工作制度汇编03-16
电力排管工程施工组织设计11-04
辽统监表A(统一表格)05-16
学生上下学交通安全应急预案02-02
通用采购合同范本03-24
农村小学英语教学的困难之我见10-14
小语种专业介绍:德语10-15
- 教学能力大赛决赛获奖-教学实施报告-(完整图文版)
- 互联网+数据中心行业分析报告
- 2017上海杨浦区高三一模数学试题及答案
- 招商部差旅接待管理制度(4-25)
- 学生游玩安全注意事项
- 学生信息管理系统(文档模板供参考)
- 叉车门架有限元分析及系统设计
- 2014帮助残疾人志愿者服务情况记录
- 叶绿体中色素的提取和分离实验
- 中国食物成分表2020年最新权威完整改进版
- 推动国土资源领域生态文明建设
- 给水管道冲洗和消毒记录
- 计算机软件专业自我评价
- 高中数学必修1-5知识点归纳
- 2018-2022年中国第五代移动通信技术(5G)产业深度分析及发展前景研究报告发展趋势(目录)
- 生产车间巡查制度
- 2018版中国光热发电行业深度研究报告目录
- (通用)2019年中考数学总复习 第一章 第四节 数的开方与二次根式课件
- 2017_2018学年高中语文第二单元第4课说数课件粤教版
- 上市新药Lumateperone(卢美哌隆)合成检索总结报告
- 封装
- 习题
- 继承
- 最新E.电子比荷的测量.05汇总
- MPN法测定食品中大肠杆菌群数
- 三严三实的内涵和意义试卷与答案(中)
- 电大会计软件运用实验报告
- 学习胸腔闭式引流的护理的笔记
- 济南房屋租赁合同(标准版)范本
- 2020年化工年终总结的范文
- 【高考冲刺】山东省潍坊市2015届高三下学期四县联考模拟训练数学(文)试题
- 聪明人投资健康 明白人储蓄健康 普通人忽视健康 糊涂人透支健康
- 2012届高三数学全国高考模拟重组预测试卷3B
- 高中化学会考必备知识点(2020年九月整理).doc
- 高考物理数学物理法解题技巧讲解及练习题
- 可编程作息时间控制器设计(DOC 31页)
- 高速养护人事迹材料
- 消防安全工作自查报告.doc
- 2018年南华大学军事医学科学院放射与辐射医学研究所723生物综合二之生物化学考研强化五套模拟题
- 人教版八年级上册历史与社会全册教案及教学设计
- 关于大学生就业指导课
- F96S荧光光度计_F96S荧光光度计价格_F96S荧光分光光度计_F96S荧光分光光度计价格
- 《平行线的性质》评课稿