资源预览内容
第1页 / 共37页
第2页 / 共37页
第3页 / 共37页
第4页 / 共37页
第5页 / 共37页
第6页 / 共37页
第7页 / 共37页
第8页 / 共37页
第9页 / 共37页
第10页 / 共37页
亲,该文档总共37页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Java习题课已学内容 第1章 java语言概述 第2章 Java语言基础 第3章 对象与类 第4章 继承和多态一、选择题 1、main()方法的返回类型是: A) int B) void C) boolean D) static 类似题: main方法是JavaApplication程序执行的入口点,关于main 方法的方法头以下哪项是合法的()? A、public static void main( ) B、public static void main( String args ) C、public static int main(String arg ) D、public void main(String arg ) JavaApplication源程序的主类是指包含有()方法 的类。 A、main方法 B、toString方法 C、init方法 D、actionPerfromed方法根据程序的构成和运行环境的不同,Java源程序分为两类: ( )程序和 ( ) 程序。 一、选择题 2、下列哪个是合法的Java标识符?() A、Treeif( a0 )if( a3 ) c = 2;else c = 3;else c = 4; A、1 B、2 C、3 D、4 一、选择题8、设有下面两个类的定义: class Person class Student extends Person longid;/ 身份证号 intscore;/ 入学总分 Stringname;/ 姓名 问:类Person和类Student的关系是() A、包含关系 B、继承关系 C、关联关系 D、无关系,上述类定义有语法错误 一、选择题9、设有下面的两个类定义: class AA void Show() System.out.println(“我喜欢Java!“); class BB extends AA void Show() System.out.println(“我喜欢C+!“); 则顺序执行如下语句后输出结果为:() AA a=new AA();BB b=new BB();a.Show();b.Show(); A、我喜欢Java! B、我喜欢C+!我喜欢C+! 我喜欢Java! C、我喜欢Java! D、我喜欢C+!我喜欢Java! 我喜欢C+! 一、选择题 10、在Java中,一个类可同时定义许多同名 的方法,这些方法的形式参数的个数、类型 或顺序各不相同,传回的值也可以不相同。 这种面向对象程序特性称为() A、隐藏B、覆盖 C、重载D、Java不支持此特性一、选择题 11、下面的是关于类及其修饰符的一些描述 ,不正确的是:() A、abstract类只能用来派生子类,不能用 来创建abstract类的对象。 B、final类不但可以用来派生子类,也可以 用来创建final类的对象。 C、abstract不能与final同时修饰一个类。 D、abstract方法必须在abstract类中声明 ,但abstract类定义中可以没有abstract方 法。 一、选择题 12、在使用interface声明一个接口时,只 可以使用()修饰符修饰该接口 A、privateB、protected C、privateprotected D、public只能是public或 者省略一、选择题 13、下列哪些说法是正确的? A、 Java 语言只允许单继承 B、 Java 语言只允许实现一个接口 C、 Java 语言不允许同时继承一个类并实 现一个接口 D、 Java 语言的单一继承使得代码更加可 靠一、选择题 类似题: 在Java程序中,通过类的定义只能实现( )继承,但通过接口的定义可以实现( ) 继承关系。 接口的定义格式为:修饰符interface接口名extends 父接 口1,父接口2类定义的完整格式是:修饰符class类名extends父类名 implements接口名1,接口名2, 一、选择题 14、用来导入已定义好的类或包的关键词是A)main B)import C)public class D)class二、填空题 1、若需要定义一个类域或类方法,应使用 ( )修饰符 2、Java中类成员的限定词有以下几种: private, public, _, _。 其中,_的限定的范围最大。被关键 字_修饰的方法是不能被当前类的 子类重新定义的方法 3、Java中所有类都是类_的子类 二、填空题 4、创建一个名为 MyPackage 的包的语句是 ,该语句应该放在程序的位置: 。 5、顺序执行以下两个语句的输出结果是: 。String s = “Hello!”; System.out.println(s.length( ); 6、如果一个Java源程序文件中定义有4个类,则使用 Sun公司的JAK编译器javac编译该源程序文件将产生( )个文件名与类名相同而扩展名为 的字节码文 件 二、填空题 7、设x = 2 ,则表达式 ( x + + ) * 3 的值是 ( ) 8、设有数组定义:int MyIntArray = 10 , 20 , 30 , 40 , 50 , 60 , 70;则执行以下几 个语句后的输出结果是 。 int s = 0 ; for (int i = 0; i j) break tp; System.out.println(“i=“ + i + “,j=“ + j); 三、读程序2、public class AppTest public static void main(String args) int i=10,j=5; System.out.println(i+“t”+j); boolean test=false; i=test?i:j; System.out.println(i+“t”+j); 三、读程序3、public class WhileTest public static void main(String args) int i=10; while(i0) System.out.println(i); i-; 三、读程序4、class Value1 int x,y; Value1(int a, int b) x=a+10; y=b; class Value2 extends Value1 Value2(int a, int b)super(a,b); public class AddTest public static void main(String args)int t;Value2 no=new Value2(10,20);t=no.x+no.y;System.out.println(“add=”+t); 三、读程序 5、public class Test extends TT public static void main(String args) Test t = new Test(“Tom“); public Test(String s) super(s); System.out.println(“How do you do?“); public Test() this(“I am Tom“); 三、读程序6、public class Person int a = 6; if (a 4) System.out.println(“Person初始化块:局部变量a的值 大于4“); System.out.println(“Person的初始化块“); System.out.println(“Person的第二个初始化块“); public Person() System.out.println(“Person类的无参数构造器“); public static void main(String args) new Person(); 三、读程序7、public class TestPrimitiveTransfer public static void swap(int a , int b) int tmp = a; a = b; b = tmp; System.out.println(“swap方法里,a的值是“ + a + “;b的值 是“ + b); public static void main(String args) int a = 6; int b = 9; swap(a , b); System.out.println(“交换结束后,实参a的值是“ + a + “;实 参b的值是“ + b); 三、读程序类似:public class TestReferenceTransfer public static void swap(DataWrap dw) int tmp = dw.a; dw.a = dw.b; dw.b = tmp; System.out.println(“swap方法里,a属性的值是“ + dw.a + “;b的值 是“ + dw.b); dw = null; public static void main(String args) DataWrap dw = new DataWrap(); dw.a = 6; dw.b = 9; swap(dw); System.out.println(“交换结束后,a属性的值是“ + dw.a + “;b属性 的值是“ + dw.b); 三、读程序8、public class Teststatic int count=0; int selfcount=0; public Test() count+;selfcount+; public static void main(String args) Test t1=new Test();Test t2=new Test(); Test t3=new Test(); System.out.println(t1.count+t2.count+t3.count); System.out.println(t1.selfcount+t2. selfcount+t3. selfcount); 三、读程序9、interface interfaceA int PROP_A = 5;void testA(); interface interfaceB int PROP_B = 6;void testB(); interface interfaceC extends interfaceA, interfaceB int PROP_C = 7;void testC(); public class TestInterfaceEx
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号