ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:19.24KB ,
资源ID:5711789      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5711789.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(类的封装与继承习题题.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

类的封装与继承习题题.docx

1、类的封装与继承习题题1以下关于继承的叙述正确的是( C )。A、在Java中类只允许单一继承B、在Java中一个类只能实现一个接口C、在Java中一个类不能同时继承一个类和实现一个接口D、在Java中接口只允许单一继承2.有继承关系时用到的关键字是(A )。( 2 分)A:extendB:extendsC:implementsD:implement3:Java变量中,以下不属于复合类型的数据类型是( D)。( 2 分)A:类B:字符型C:数组型D:接口4:java中定义数组名为 abc,下面(B )可以得到数组元素的个数。( 2 分)A:abc.length( )B:abc.lengthC:l

2、en(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)。(

3、 2 分)A:Java不提供goto语句,所以也就没指定goto作为关键字。B:Java没有指针。C:Java没有联合和结构D:Java只有单继承没有多重继承。8:若需要定义一个类域或类方法,应使用( B)修饰符。( 2 分)A:staticB:packageC:privateD:public9:下列说法( C)是正确的。( 2 分)A:程序执行到break语句是一定会结束所有的循环B:程序执行到continue语句时会结束当前循环C:break语句和continue语句都可以和标签协同使用D:continue语句和break语句的作用相同10:以下说法正确的是(D )。( 2 分)A:每个J

4、ava类都至少有一个构造方法,如果没有则机器自动生成一个默认的构造方法。B:如果类里定义了一个或多个构造方法,那么java也提供默认的构造方法C:每个Java类中用户必须定义至少一个构造方法。D:以上都不对11:对封装的理解正确的是(A )。( 3 分)A:封装就是把对象的属性和行为结合成一个独立的单位。B:封装就是把对象完全隐蔽起来,不让外界访问。C:封装性是一个使用问题。D:封装和抽象是一回事。12:对成员的访问控制保护最强的是(C )。( 3 分)A:publicB:缺省C:privateD:protected13:类Test1定义如下: 1.public class Test12. p

5、ublic 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:构造函数与类同

6、名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:程序将输出:= = succeededB:程序将输出: .equals() succeededC:程序将输出:= = succeeded .equal

7、s() succeededD:程序无输出16:关于以下程序代码的说明正确的是( C)。1class 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);

8、12 13 ( 2 分)A:5行不能通过编译,因为引用了私有静态变量B:10行不能通过编译,因为x是私有静态变量C:程序通过编译,输出结果为:x=103D:程序通过编译,输出结果为:x=102三、程序阅读题1、以下程序的输出结果为_ Peter is 17 years old!_。public class Person String name; int age; public Person(String name, int age) this.name = name; this.age = age; public static void main(String args) Person c =

9、 new Person(Peter, 17); System.out.println(c.name + 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; p

10、ublic 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;

11、 public void setWeight(float weight) this.weight = weight; private void out() System.out.println(name + 体重: + weight + 斤); public static void main(String args) Tom.name = 汤姆猫; Tom cat = new Tom(); cat.setWeight(20); cat.out(); 4、以下程序的输出结果:姓名:Tom 年龄:15家庭住址: 金水区 学校:九中 电话: 66123456public class Father S

12、tring name, address, tel; int age; public Father(String name, int age) this.name = 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; pu

13、blic 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 i

14、nt a = 1, 2, 3, 4, 5 ; void out() for (int j = 0; j a.length; j+) System.out.print(aj + ); 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.to

15、String( ); 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 ,

16、 80 , 90 ; for ( i = 0 ; i a.length ; i + ) if ( ai%3 = = 0 ) s += ai ; 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

17、, 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=301以下程序的输出结果为 相等_ 。class StringTest1 public static void main(String args) String s1=hello; String s2=new Stri

18、ng(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 ( ajak ) k = j; int temp

19、 =ai; ai = ak; ak = temp; for ( i =0 ; ia.length; i+ ) System.out.print(ai+ ); 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 = n

20、ew 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 ); publi

21、c 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类,添

22、加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();

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1