Sie sind auf Seite 1von 6

Core Java

Name :

Emp Id :

Max. Marks : 25

1. What is the result of compiling and executing this program? class Abc

{

 

public static void main(String args[])

{

int x, y, z; System.out.println(x+y+z);

}

}

a)

Prints 0

b)

Prints null

c)

Compile Time Error

d)

Runtime Error

2. Compile time errors are generated at which line?

class MWC101

{

public static void main(String[] args)

{

int[] a1 = new int[];

// 1

int a2[] = new int[5];

// 2

int[] a3 = new int[]{1,2};

// 3

int []a4 = {1,2};

// 4

int[] a5 = new int[5]{1,2,3,4,5}; // 5

}

}

a) 1

b) 2

c) 3

d) 4

e) 5

3. What is the result of attempting to compile and execute the following classes

// 1

class GRC2 {protected static void main(String[] args) {}} // 2

// 3

class GRC1 {public static void main(String[] args) {}}

class GRC3 {private static void main(String[] args) {}}

a) Compile time error at line 2, 3

b) Can execute all the 3 classes

c) Only GRC1 can be executed

4.

Which of these does not belong to Java keywords

a) transient

b) serializable

c) synchronized

d) finally

e) finalize

5. What will be the result of this code

class MCZ13 { public static void main (String[] args) { String s = null; System.out.print(s);

}}

a) null

b) NullPointerException

c) Compiler error

d) None of the above

6. What will be the result of this code

class MWC103 { public static void main(String[] args) { int[] a1 = {1,2,3}; int []a2 = {4,5,6}; int a3[] = {7,8,9};

System.out.print(a1[1]+","+a2[1]+","+a3[1]);

}}

a)

Prints 2,5,8

b)

Prints 1,4,7

c)

Compile time error

d)

Prints 3,6,9

7. Which of these is invalid while compilation

class MWC104

 

{

 

public static void main(String[] args) {

int[5] a1;

// 1

int []a2;

// 2

int[

]a3; // 3

int a4[];

// 4

}}

a)

1

b)

2

c)

3

d)

4

8. Can we call the main method from some other class

a) True

b) False

9. What is the output of this program when class C is run

class A

{

public static void abc()

{

System.out.println(“hi”);

}

}

class B extends A

{

public static void abc()

{

System.out.println(“hello”);

}

}

class C

{

 

public static void main(String args[])

{

A a1 = new B();

a1.abc();

}

}

a) hi

b) hello

c) runtime error

d) compile time error

10. Which of these is valid

a) boolean b = True

b) Boolean b = new Boolean(true);

c) Boolean b = FALSE;

d) boolean B = false;

11. Which of these are marker interface

a) Runnable

b) Serializable

c) Comparable

d) Cloneable

12. When is finalize() method called

a) Before object is removed from heap memory

b) After removing the object

c) Whenever overridden in the subclass

d) None of these

13. Which of these statements holds good for the default constructor

a) Default constructor is added by the JVM

b) Default constructor is added by the compiler

c) Default constructor is only created when there is no other constructor available

14. Which of these task are performed by the JVM

a) Class Loading

b) Byte Code Verification

c) Execution of Bytecodes

d) All the above

15. Which of these is not possible

a) Interface extends Interface

b) Class implements Interface

c) Class extends Interface

d) Interface implements Interface

16. Which of these statements are true

a) Interface contains all the fields as static and final

b) All methods in an abstract class is by default abstract methods

c) Abstract class can contain final variables

d) Abstract class can be instantiated

e) Abstract class contains constructor

17. What is the output of the below program static class Abc

{

 

static int a=10; public static void main(String args[])

{

System.out.println(a+5);

}

}

a)

Compile time error

b)

Runtime Exception

c)

Prints 15

d)

Prints 5

18. Which of these is true

a) We can have try without catch and finally

b) We can have try and finally without catch

c) We can have try and catch without finally

d) All the above

19. State which is true

a) We can have constructor overloading

b) Constructor can have return types

c) Methods can have the same name that of the class name

d) Outer class can be declared as private

20. What will appear in the standard output when you run the Tester class?

class Tester

{

 

int var; Tester(double var)

{

this.var = (int)var;

}

Tester(int var)

{

this("hello");

}

Tester(String s)

{

this();

System.out.println(s);

}

Tester()

{

System.out.println("good-bye");

}

public static void main(String[] args)

{

Tester t = new Tester(5);

}

}

a) nothing

b) "hello"

c) 5

d) "hello" followed by "good-bye"

e) "good-bye" followed by "hello"

21. Which class should be extended to create a custom unchecked exception class

a) RuntimeException

b) Exception

c) ArithmeticException

d) NullPointerException

22. Which of these are the methods of Thread class

a) wait()

b) suspend()

c) resume()

d) notify()

e) All the above

23. State which is true about >> and >>> operator

a) >> is to shift even the sign bit

b) >>> is to shift the sign bit

c) Both result the same value

d) None of the above

24. Which of the following will compile without error

a) import java.awt.*; package Mypackage; class Myclass {}

b) package MyPackage; import java.awt.*; class MyClass{}

c) /*This is a comment */ package MyPackage; import java.awt.*; class MyClass{}

25. Which two of these statements are true about constructors? (Choose two.)

a. Constructors must not have arguments if the superclass constructor does not have arguments.

b. Constructors are not inherited.

c. Constructors cannot be overloaded.

d. The first statement of every constructor is a legal call to the super() or t this()method.