java笔试题5

更新时间:2024-01-05 03:33:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

1、下列代码的输出结果:

public class test09 {

public static void main(String[] args) { Super s = new Sub(); s.test(); } }

class Super{

public void test(){ this.t();this.g(); }

public void t(){System.out.println(\);} private void g(){System.out.println(\);} }

class Sub extends Super{

public void t(){System.out.println(\);} private void g(){System.out.println(\);} }

A.Sub.t(); Sub.g(); B.Sub.t(); Super.g(); C.Super.t(); Super.g(); D.Super.t(); Sub.g(); 答案:B

2、下列代码的输出结果是: abstract class Vehicle{ public int speed(){ return 0; } }

class Car extends Vehicle{ public int speed(){ return 60; } }

class RaceCar extends Car{ public int speed(){ return 150; }

}

public class TestCar { public static void main(String[] args) { RaceCar racer = new RaceCar(); Car car = new RaceCar(); Vehicle vehicle = new RaceCar(); System.out.print(racer.speed()+\ +vehicle.speed()); } } A.0,0,0

B.150,60,0 C.150,150,150

D.抛出运行时异常 答案:C

3、下列代码运行的结果是: public class Hello { String title; int value;

public Hello(){ title +=\ }

public Hello(int value){ this.value = value; title =\ }

public static void main(String[] args) { Hello c = new Hello(5); System.out.println(c.title); } }

A.Hello

B.Hello World C.Hello World 5 D.运行后无输出 答案:A

4、执行下列语句: int a = 0x9af700; a <<= 2;

变量a的值为:()。 A. 0x26bdc00 B. B. 0xc6bdc00

C. 0x3fa0000 D. 0x7e02ffff 答案:A

5、下列语句创建对象的总个数是:()。 String s=”a”+”b”+”c”+”d”; A. 1 B. 2 C. 3 D. 4 答案:A.

6、类A,B的定义如下: class A {

private int a = 100; A() {

System.out.print(\ System.out.println(a); } }

class B extends A { private int a = 200; B() {

System.out.print(\ System.out.println(a); } }

运行下面的代码: new B();

输出的结果是:()。 A. A() 100

B() 200 B. A() 200

B() 200 C. B() 200

A() 100 D. B() 200

A() 200

7、下列不属于Java运算符的是()。 A.!= B.<> C.>>

D.<< E.>>> F.<<<

正确答案:BF

8、下列属于不合法Java标识符的是()。 A._avaj B.5save C.Avaj5 D.$80

正确答案:B

9、运行下列程序:

String str = \String str1 = \int index = 0;

while ((index = str.indexOf(str1, index)) != -1) { System.out.print(index+””); index += str1.length(); }

控制台输出的结果是:()。 A.1 10 21 B.2 11 22 C.3 13 23 D.5 13 22 正确答案:B

10、class Card{}下列不属于Card类构造方法的是:() A.Card(){}

B.public Card(){}

C.public void Card(){} D.private Card(){} 正确答案:C

11、 以下程序的输出结果是: ()。 public class Super { public Super() {

System.out.println(\ } }

public class Sub extends Super{ public Sub() {

System.out.println(\ }

public static void main(String[] args) { Super fc = new Super(); Sub cc = new Sub(); } }

A.Super Super Sub B.Super Sub C.Sub Super D.Super Sub Sub

正确答案:A

12、A类中有一个方法:protected int print(String str){},B类继承A类,以下方法能在B类中重写A类中print()方法的是: ()。 A.public int print(String str){} B.private int print(String str){} C.private void print(String str){} D.public void print(String str){} 正确答案:A

13、运行下面的语句: String s=\if(s==s+0){

System.out.println(\}

编译,运行的结果是:()。 A.Hello World B.无输出

本文来源:https://www.bwwdw.com/article/7q8x.html

Top