Java基础知识英文选择题5——Keyword, Constrctor, etc.

1. Consider the following statement which is defined in a class( let's call it class Test). The keyword static : private static int serial = 0;

A. means that serial is a constant.

B. ensures that only one instance of serial exists and it will be shared by all objects of type Test.

C. means that serial should be capitalized( e.g. SERIAL )to comply with Java naming conventions.

D. results in a syntax error because it is missing the ketword final.

Correct Answer : B

2. Which of the following statements about constructors in java is true?

A. a class must define at least one constructor.

B. a class can define more than one constructor.

C. a constructor must be defined as public.

D. a constructor must be defined as static.

Correct Answer : B

3. Which of the following catagorizations can be applied to both the data fields and the methods in a java class?

A. native and non-native.

B. default and non-default.

C. static and non-static

D. abstract and non-abstract

Correct Answer : C

4. What is used to indicate that a method doesn't return a value?

A. the keyword void

B. the name of the class to which it belongs

C. the omission of the return type

D. the keyword static

Correct Answer : A

5. When a subclass defines an instance method with the same return type and signature as a method in its parent, the parent's method is said to be

A. hidden

B. overriden

C. private

D. overloaded

Correct Answer : D

6. If a class contains a constructor, that constructor will be invoked__

A. each time an object of that class is instantiated.

B. once the first time an object of that class is instantiated.

C. each time an object of that class goes out of scope.

D. once at the beginning of any program that uses that class.

Correct Answer : A

7. Which is a java access modifier used to designate that a particular data field will not be inherited by a subclass?

A. final

B. default

C. protected

D. private

Correct Answer : D

8. Consider the following java program statement:

import java.io.*;

public class Test {
    public test() {
        System.out.println("default");
    }
    public test(int i) {
        System.out.println("non-default");
    }
    public static void main(String[] args) {
        test t = new test(2);
    }
}

which of the following will be output during execution of the program segment?

A. the line of text "non-default".

B. the line of text "default".

C. the line of text "non-default" followed by the line of text "default".

D. the line of text "default" followed by the line of text "non-default".

Correct Answer : A

9. Consider the following java class definitions:

public class object1 {
    protected String d(){
        return "hi";
    }
}

public class object2 extends object1 {
    protected String d(){
        return super.d();
    }
}

which of the following statements is(are) true regarding the definitions?

i. class object2 inherits from class object1.

ii. class object2 overrides method d.

iii. method d returns equivalent results when executed from either class.

A. i and ii only.

B. i, ii, and iii

C. iii only.

D. i and iii only.

Correct Answer : B

10. If the method int sum(int a, int b) is defined in a java class C, which of the following methods cannot coexist as a different method in class C?

A. int sum(float a, int b)

B. int sum(int x, float y)

C. int sum(int x, int y)

D. float sum(int x, float y)

Correct Answer : C

(部分题目来自网络,如有侵权,请联系文章作者删除)

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值