java 数组继承,JAVA类数组继承测试题目

此博客内容涉及JAVA编程的基础知识,包括数据类型、数组、继承、关键字、标识符等概念,通过一系列的选择题和代码片段来考察理解。涵盖如浮点数赋值、数组操作、方法调用、包导入、变量初始化、字符串操作、类型转换等方面的问题。
摘要由CSDN通过智能技术生成

41528d3028836879cd698677c3999917.gifJAVA类数组继承测试题目

JAVA类、数组、继承测试题目 第一部分:选择题目 Question 1) 下面哪行语句在编译时不会出现错误或者警告信息: a) float f = 1.3; b) char c = “a“; c) byte b = 257; d) boolean b = null; e) int i = 10; Question 2) 在编译运行下面的代码时,会发生什么情况? public class MyClass { public static void main(String args[]) { a(arguments); } public void a(String[] args) { System.out.println(args); System.out.println(args[1]); } } 1) 错误,不能在静态方法中调用方法void a() 2) 错误,main()方法中有错误 3) 错误,数组必须要包含参数 4) a()方法必须被声明为String型 Question 3) 下面哪项语句编译不会出错: 1) import java.awt.*; package Mypackage; class Myclass {} 2) package MyPackage; import java.awt.*; class MyClass{} 3) /*This is a comment */ package MyPackage; import java.awt.*; class MyClass{} Question 4) 1) -128 to 127 byte类型数据的取值范围是: 2) (-2 power 8 )-1 to 2 power 8 3) -255 to 256 4) 由JAVA虚拟机决定 Question 5) 如果下面的语句在命令行下执行,会得到什么输出结果? java myprog good morning public class myprog{ public static void main(String argv[]) { System.out.println(argv[2]) } } 1) myprog 2) good 3) morning 4) Exception raised: “java.lang.ArrayIndexOutOfBoundsException: 2“ Question 6) 下面哪些不是JAVA的保留关键字: 1) if 2) then 3) goto 4) while 5) case Question 7) 下面哪些是JAVA中合法的标识符? 1) 2variable 2) variable2 3) _whatavariable 4) _3_ 5) $anothervar 6) #myvar Question 8) 编译下面的代码会出现什么结果? public class MyClass{ static int i; public static void main(String args[]){ System.out.println(i); } } 1) 错误,Variable i may not have been initialized 2) null 3) 1 4) 0 Question 9) 编译运行下面的代码会出现什么结果? public class Q { public static void main(String args[]){ int anar[] = {1,2,3}; System.out.println(anar[1]); } } 1) 1 2) Error anar is referenced before it is initialized 3) 2 4) Error size of array must be defined Question 10) 编译运行下面的代码会出现什么结果? public class Q { public static void main(String args[]){ int anar[]= new int[5]; System.out.println(anar[0]); } } 1) Error: anar is referenced before it is initialized 2) null 3) 0 4) 5 Question 11) 如果编译运行下面的代码,你会得到什么样的结果? abstract class MineBase { abstract void a(); static int i; } public class Mine extends MineBase { public static void main(String argv[]){ int[] ar = new int[5]; for(i = 0;i >4: 5. System.out.println(“N= “+N); 6. } 7. } a) The compiler will object to line 4 combining a long with an int. b) The program will compile and run, producing the output “N=0“. c) The program will compile and run, producing the output “N=1“. d) A rutime exception will be thrown. Question 30: 在编译运行下面的代码时,会产生什么样的运行结果? 1. public class Example{ 2. public Boolean flags[]=new Boolean[4]; 3. public static void main(String[] args){ 4. Example E=new Example(); 5. System.out.println(“Flag 1 is “+E.flags[1]); 6. } 7. } a) 字符串 “Flag 1 is true“ 将会输出到屏幕上。 b) 字符串 “Flag 1 is false“ 将会输出到屏幕上。 c) 字符串 “Flag 1 is null“ 将会输出到屏幕上。 d) 编译时,第2行代码会有问题。 Question 31: [Check all correct answers] 下面选项中,哪些是合法的Java代码?(选出所有正确的答案) a) String A=“abcdefg“; A-=“cde“; b) String A=“abcdefg“; A+=“cde“; c) Integer J=new Integer(27); J-=7; d) Integer J=new Integer(27); J--; Question 32: 下面给出类Demo的定义,其中“XXXX”代表一个访问限制修饰关键字: public class Demo extends Base{ XXXX String userName; public void setName(String s){ userName=s;} public void showName(){ System.out.println(“Name is “+userName); } public String getName(){ return userName; } } Select the modifier which would be used to give only classes in the default package or classes derived from Demo, direct access to the userName String variable. 再下面的关键字中选取一个用来代替“XXXX”,要求在类Demo所在的默认的包中或者类中,能够访问到String类型的变量userName。请选择出正确的答案。 a) public b) blank (ie - the line would read “String userName :“) c) protected d) private Question 33: 在应用程序中给定下面定义的方法: 1. public String setFiletype(String fname){ 2. int p=fname.indexOf( . ); 3. if(p>0) fname=fname.substring(0,p); 4. fname+=“.TXT“; 5. return fname; 6. } 另外给定下面的几行代码: 7. String TheFile=“Program.java“; 8. File F=new File(setFileType(TheFile)); 9. System.out.println(“Created “+TheFile); What will be printed by the statement in line 9? 上述程序中,第9行会输出什么结果? a) “Created Program.java“ b) “Created Program.txt“ c) “Created Program.java.txt“ Question 34: 如果编译运行下面的代码会得到什么结果? 1. public class EqualsTest{ 2. public static void main(String args[]){ 3. byte A=(byte)4096; 4. if(A==4096) 5 System.out.println(“Equal“); 6 else 7 System.out.println(“Not Equal“); 8 9 } a) 编译错误;编译代码时,第三行会出现精度损失。 b) 正常编译,程序运行会输出结果:“Not Equal“. c) 正常编译,程序运行会输出结果: “Equal“. Question 35: 如果编译运行下面的代码会得到什么结果? 1. public class EqualsTest{ 2. public static void main(String args[]){ 3. Long LA=new Long(7); 4. Long LB=new Long(7); 5. if(LA==LB) System.out.println(“Equal“); 6. else System.out.println(“Not Equal“); 7. } 8. } a) 编译代码时,第5行会抛出一个运行时异常。 b) 程序编译运行会输出结果:“Not Equal“; c) 程序编译运行会输出结果: “Equal“. Question 36: [Check all correct answers] 下面给出类Demo的代码: public class Demo extends Base{ private int count; public Demo(){ System.out.println(“A Demo object has been created“); } protected void addOne() {count++; } } 下面关于变量“count”叙述哪些是正确的? a) 当一个新的Demo的对象创建时,变量count的初始值为0 b) 当一个新的Demo的对象创建时,变量count的初始值没有被定义 c) 类Base中有方法或者代码能够修改变量count的值 d) 变量count的值仅能够被方法addOne()修改 Question 37: [Check all correct answers] 下面哪行代码会导致一个编译错误? a) float F=4096.0; b) double D=4096.0; c) byte B=4096; d) char C=4096; Question 41: 运行下面的程序时,在命令行输入:java Demo alpha beta gamma public class Demo{ public static void main(String args[]){ int n=3; System.out.println(“The word is “+args[n]); } } 程序会产生什么结果? a) 在屏幕上输出: “The word is beta“ . b) 在屏幕上输出:“The word is gamma“ . c) 系统报告错误信息: ArrayIndexOutOfBoundsException in the main . d) 系统报告错误信息: a NullPointerException in the main . Question 43: 如果编译运行下面的代码会得到什么结果? public class EqualsTest{ public static void main(String args[]){ char A= \u0005 ; if(A==0 x0005L) System.out.println(“Equal“); else System.out.println(“Not Equal“); } } a) 编译错误,并产生提示信息:“Invalid character in “ in line 3. b) 正常编译,运行时输出: “Not Equal“. c) 正常编译,运行时输出: “Equal“. Question 44: 下面对于整型数组的定义,哪些选项是正确的?(选择出所有答案) a) int scores[]; b) int[] scores; c) int scores={0,0,0,0}; Question 45: 假设下面程序已经正常编译生成了Demo.class文件,并且位于在当前目录下 public class Demo{ public static void main(String args[]){ int n=1; System.out.println(“The word is “+args[n]); } } 请选择正确的选项,使得程序在运行时能够输出结果:“The word is gamma“ a) Demo alpha beta gamma delta b) java Demo alpha beta gamma delta c) java Demo beta gamma delta d) java Demo.class beta gamma delta e) java Demo.class alpha beta gamma delta Question 46: 如果编译运行下面的代码会得到什么结果? public class EqualsTest{ public static void main(String args[]){ Object A=new Long(7); Long L=new Long(7); if(A.equals(L)) System.out.println(“Equal“); else System.out.println(“Not Equal“); } } a) 正常编译,运行时在屏幕上输出: “Equal“. b) 正常编译,运行时在屏幕上输出:“Not Equal“. c) T程序第5行会有编译错误。 Question 47: 编译下面的代码会得到什么运行结果? public class SiteInfo{ String webSite=““+ / +“default.htm“; public String getSite() { return webSite; } } a) The code will compile without problem. b) The compiler will report an error “ : expected“ for the statement in line 2. c) The compiler will object to the char literal in line 3. Question 49: 文件Derived.java.代码如下 public class Base extends Object{ String objType; public Base(){ objType=“I am a Base type“; } } public class Derived extends Base{ public Derived() { objType=“I am a Derived type“; } public static void main(String args[]){ Derived D=new Derived(); } } 当文件被编译时,会有什么执行结果? a) 会创建两个类文件: Base.class and Derived.class. b) 程序的第一行会有错误。 c) 类之间的继承关系不成立 Q. 50 Consider the following program: public class Test { public static void main (String args []) { boolean a = false; if (a = true) System.out.println(“Hello“); Else System.out.println(“Goodbye“); } } What is the result: A. Program produces no output but terminates correctly. B. Program does not terminate. C. Prints out “Hello“ D. Prints out “Goodbye“ Select the most appropriate answer. Q. 52 Carefully examine the following class: public class Test5 { public static void main (String args []) { /* This is the start of a comment if (true) { Test5 = new test5(); System.out.println(“Done the test“); } /* This is another comment */ System.out.println (“The end“); } } What is the result: A. Prints out “Done the test“ and nothing else. B. Program produces no output but terminates correctly. C. Program does not terminate. D. The program will not compile. E. The program generates a runtime exception. F. The program prints out “The end“ and nothing else. G. The program prints out “Done the test“ and “The end“ Select the most appropriate answer. f Q. 57 Given is this class: class Loop{ public static void main(String[] agrs){ int x=0; int y=0; outer: for(x=0;x> } } } } // main } // class 下面那条语句可以替换到>这个位置,使得outerloop循环可以完成? a) continue middle; b) break outer; c) break middle; d) continue outer; e) none of these Q. 59 class StringTest{ public static void main(String[] args){ // // String comparing // String a,b; StringBuffer c,d; c=new StringBuffer(“Hello“); a=new String(“Hello“); b=a; d=c; if( > ) {} } } // class 下面的四个表达式中,哪个可以在StringTest.class中的>这个位置返回值为true(即使得判断条件成立): a) b.equals(a) b) b=a; d=c; c) d==c d) d.equals(c) Q. 60 下面哪些是合法的标识符? a) %fred b) *fred c) thisfred d) 2fred e) fred Question for 61-69 1、 下列哪种类成员修饰符修饰的变量能够在本类中被访问到? A、 protected B、 public C、 default D、 private 2、 在Java语言中哪一个包是被自动导入的? A、 java.lang B、 java.awt C、 java.io D、 java.applet 3、 下面关于接口的说法不正确的是? A、 接口中定义的方法都是抽象的 B、 接口所有的方法一定都是public属性的 C、 用于定义接口的关键字是implements D、 接口是Java中的特殊类,包含常量和抽象方法 4、 为了区分类中重载的同名的不同方法,要求: A、 采用不同的形式参数列表 B、 使用不同的参数名称 C、 修改访问权限 D、 返回值的数据类型不同 5、 子类的对象能否直接向其父类对象赋值?父类对象能否向其子类对象赋值? A、 能,能 B、 能,不能 C、 不能,不能 D、 不能,能 6、 如果创建一个子类覆盖父类的public属性的方法,则该对象的方法可以使用的访问修饰符号有: A、 public B、 private C、 protected D、 default 7、 下面关于Java的说法中正确的是: A、 Java中的类可以有多个直接父类 B、 抽象类可以实例化 C、 最终类可以作为其他类的父类 D、 Java中的接口支持继承 8、 定义类时不能使用的关键字是: A、 public B、 private C、 protected D、 default 9、 下面关于Java说法不正确的是: A、 abstract和final能同时修饰一个类 B、 抽象类做抽象父类,也可以做抽象子类 C、 抽象方法不一定必须定义在抽象类中,同样也可以存在于接口中 D、 声明为final的方法不能在子类中被重新定义

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值