分享一套JAVA英文笔试题(一)

1.What is the output of the following code?

 

public class TestEquals{
    public static void main(String[] args){
        String str1 = "test";
        String str2 = new String("test");
        String str3 = "test";
        System.out.println(str1 == str2);
        System.out.println(str1 == str3);
        System.out.println(str1.equals(str2));
        System.out.println(str1.equals(str3));
    }
}

 

 

2.Equals hash codes imply that the objects are equals.True or False?

 

3.What is the size of the character data type in bytes?

 

4.Check the following code

 

class A {
    public void doSomething(){}
}
class B extends A {
    private void doSomething(){}

}

a.Is it an example of method overloading OR method overriding?

 

b.Will the program throw compilation error,runtime error OR compile and run without any errors?

 

5.Check the following code

 

class C {
    private void doSomething(){}
}
public class D extends C {
    public void doSomething(){}
}

a.Is it an example of method overloading OR method overriding?

 

b.Will the program throw compilation error,runtime error OR compile and run without any errors?

 

6.Let us assume you only have a single user-defind public java class,the java compiler and java interpreter with you.It does not have a public static void main() method.Is it possible to execute any random code of your choice in such a java class?

 

For this question,you are NOT supposed to use any other API class or user-defined class.if you think it is possible,please write the code of the single class.if you think otherwise,please explain why it is not possible to execute code in such a class.

 

7.Can an abstract class have a "public static void main(String[] args)" method?

 

8.Check the following code

interface SuperInterface {
    void walk();
}
interface SubInterface implements SuperInterface {
    void run();
}
public class TsetInterface implements SubInterface {
   @Override
    public void walk(){
        System.out.println("I am walking");
    }
   @Override
    public void run(){
        System.out.println("I am running");
    }
    public static void main(String[] args) {
         TestInterface ti = new TestInterface();
         ti.walk();
         ti.run();
    }
}

 Which of the following is correct?

a Code throws compilation error

b Code throws run-time error

c Code runs fine and output is:

I am walking

I am running

 

9.When calling the main() method of a java class,if we do not provide any arguments on the command line,then the string array of main() method-will it be empty or null?

 

10.When differentiating overloaded methods does the compiler consider the return type of the method?

 

11.Can we override an overloaded method?

 

12.Can you overload the "public static void main(String[] args)" method in java?

 

13.Can you override a static or final method in java?

 

14.Can you declare a constructor as final in java?

 

15.Is java pass-by-value Or pass-by-reference?

 

16.Can an interface implement another classes?

 

17.Which object oriented concept is achieved by using overloading and overriding?

 

18.Which class is extended by all other classes?

 

19.Can a transient variable be serialized?

 

20.Is the String class declared final?

 

21.When does the garbage collector call the finalize() method?

 

22.Write the signature of the finalize() method?

 

23.Object E has reference to object F and object F has reference to object E.There are no other references to objects E and F.Select the correct answer.

a. No objects will be garbage collected as E has reference to F and F has reference to E.

b. Only object E will be garbage collected

c. Only object F will be garbage collected

d. Both objects E and F will be garbage collected

 

24.Can we call the garbage collector from java code?if yes,how?if no,why not?

 

25.Can we force garbage collector to run?

 

26.How can you monitor garbage collection?

 

27.Can you change values of an immutable object?

 

28.List the different access specifiers

 

 

1. The name of a Java source file (a) has no restrictions (b) must be the same as the class it defines, ignoring case (c) must use the extension .class (d) must be the same as the class it defines, respecting case 2. Which of the following statements is (are) true about the use of an asterisk (*) in a Java import statement? Ⅰ.It does not incur run-time overhead. Ⅱ.It can be used to import multiple packages with a single statement. Ⅲ.It can be used to import multiple classes with a single statement (a) I, II, and III (b) I and III only (c) I only (d) III only ..... 9. According to the Java code conventions, files that contain Java source code have the suffix _____, and compiled bytecode files have the suffix _____. (a) .class, .java (b) .class, .javac (c) .java, .class (d) .javac, .class 10. As an aid in debugging a program in Java, print statements may be used to display which of the following types of information? I. The names of methods being called II. The values of the parameters of a method Ⅲ. The values of the instance variables of a class (a) I and II only (b) I and III only (c) II and III only (d) I, II, and III 1. In a UML class diagram's representation of a class, the top, middle, and lower rectangular compartments respectively describe the _____ of the class. (a) name, attributes, and methods (b) name, methods, and constants (c) attributes, methods, and name (d) attributes, methods, and constants 2. UML class diagrams can describe which of the following? I. The internal structure of classes Ⅱ. Relationships between classes (a) I and II (b) II only (c) None (d) I only ....... 1.The term class variable is a synonym for (a) a private data field (b) a static data field (c) a read-only variable (d) an instance variable 2. Consider the following Java program segment. 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); } } ......... 9. 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) private (b) hidden (c) overloaded (d) overridden 10. Which is a Java access modifier used to designate that a particular data field will not be inherited by a subclass? (a) final (b) protected (c) private (d) default 1. Consider the following Java program segment. String[] str = {"Three","Two","One"}; for (int i = 0; i < str.length; ++i) { System.out.println(str[i]+"/"); } What will be output upon execution of the program segment? (a) Three/Two/One/ (b) Three,Two,One (c) One,Two,Three (d) One/Two/Three/ 2. Consider the following Java program segment. int[] arr; arr = new int[3]; arr[2]=19; arr[1]=17; arr[0]=15; Which of the following Java statements is syntactically correct and semantically identical to the program segment? (a) int[] arr= {15, 17, 19}; (b) int[3] arr = {15, 17, 19}; (c) int arr = {15, 17, 19}; (d) int arr[3]= {15, 17, 19}; ........ 2. Which of the following statements is (are) true about any abstract method in Java? I. It contains no definition. Ⅱ. It cannot be declared public. (a) I and II (b) I only (c) None (d) II only 3. Consider the following Java program fragment. public void drive(Vehicle v) { ... } ... drive(obj); The method call drive(obj) is valid if obj is which of the following? I. A descendent of class Vehicle II. An ancestor of class Vehicle Ⅲ. An object of class Vehicle (a) I and III only (b) I, II, and III (c) III only (d) II and III only .....
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值