You are on page 1of 13

[Type here]

Core Java
Post Training Assessment

1. A method is defined in a class as :


void processUser(int i) { }
If this method is overridden in a sub class,_

a. the new method should return int


b. the new method can return any type of values
c. the argument list of new method should exactly match that of overridden method
d. the return type of new method should exactly match that of overridden method

2. What will be the output?

public class Test1{


public static void main(String[] args){
int arr[] = new int[3];
for(int i = 0;i < arr.length;i++){
System.out.println(arr[i]); }}}

a. 000
b. ArrayIndexoutOfBoundsException
c. NullPointerException
d. null null null

3. Which of the following are valid array declarations?

a. int arr[] = new int[];


b. float arr[10] = new fl
c. double []arr = new double[10];
d. None Of the Above.

4. What will be the output ?

public class Test5{


public void Test5(){
System.out.println("Constructor1");}
public Test5(){
System.out.println("Constructor2"); }
public static void main(String[] args){
Test5 t5 = new Test5();}}

a. Constructor1
b. Constructor2
[Type here]

c. Constructor1 Constructor2
d. Compiler Error

5. Which of the following are not wrapper classes?


a. String
b. Integer
c. StringBuffer
d. Boolean

6. Java Identifiers must start with a letter, dollar sign ($), or underscore (_).

True / False

7. What is the output ?

Class C{
int i;
public static void main (String[] args) {
int i;
private int a = 1;
protected int b = 1;
public int c = 1;
System.out.println(a+b+c); }

a. compiletime error at lines 1,2,3,4,5


b. compiletime error at lines 2,3,4,5
c. compiletime error at lines 5,6,7
d. prints 3
e. None of the above

8. What is the result of attempting to compile and run the program ?.


Class C {
public static void main(String[] args) {
int[]a1[]=new int[3][3];
int a2[4]={3,4,5,6};
int a2[5];}}

a. compiletime error at lines 3,4,5


b. compiltime error at line 4,5
c. compiletime error at line 3
d. Runtime Exception
e. None of the above

9. class A{
static String m(float i) {return "float";}
static String m(double i) {return "double";}
[Type here]

public static void main (String[] args) {


int a1 = 1; long b1 = 2;
System.out.print(m(a1)+","+ m(b1));}}

a. prints float,foat
b. prints float,double
c. prints double,double
d. compile time error
e. None of the above

10. The length of an Array ‘abc’ can be found using :

a. abc.length
b. abc.length()
c. abc.size
d. abc.size()

11. The constructor of super class can be called using

a. this();
b. super.constructor();
c. super();
d. super(Object);

12. ________ stops MultiThreading.

a. Stop()
b. Synchronization
c. Yield()
d. None of these

13. What is the value of String s in this code ?

Properties p=new Properties();


String s=p.getProperty(“JavaVersion”);

a. Gets Properties of JavaVersion .


b. Gets version 1.8
c. Searches “ JavaVersion”
d. Gets version 1.8.16

14. What is the result of following code ?

class Animal
{ void method () throws Exception
{ }
[Type here]

Animal( String name )


{
System.out.println(name);
}}

class dog extends Animal


{
void method () throws Exception
{ }
}

class test
{
public static void main ( String [] args )
{
new Animal("Giraffe");
}
}

a. Prints Giraffe
b. Compile error
c. Runtime error
d. Prints nothing
e. None of the above

15. ________ are used to store, retrieve and manipulate data and to transmit data from one method to another.

a. Objects
b. Constructors
c. Collections
d. Streams

16. ______ is data structure which stores the key/value pairs in the List.

a. HashMap
b. LinkedList
c. Queue
d. HashTable

17. What is the result of following code ?

int []arr = {1,2,3,4};


for ( int i : arr )
[Type here]

{
arr[i] = 0;
}

for ( int i : arr )


{
System.out.println(i);
}

a. Prints 0 1 2 3
b. Prints 0 0 0 0
c. Prints 0 0 3 0
d. Prints 0 2 0 0
e. Compile error
f. Runtime Exception occurs.

18. What is the o/p of following code?

import java.util.*;
class test
{
private int x;
test(int input) { x = input; }
public static void main( String args[] )
{
List list = new ArrayList();
list.add(new test(2));
list.add(new test(2));
Collections.sort(list);
}

public int compare( test t1 , test t2 )


{
return t1.x - t2.x;
}
}

a. Sorts test instances based on variable x


b. Sorts the instances in ascending order
c. Sorts the instances in descending order.
d. None of the above.

19.
class sup
{
static void method(){System.out.println("Super");} // 1
}
[Type here]

class test extends sup


{
public static void main(String args[]) {}
static void method(){System.out.println("test");}
}

What class modifier(s) can be inserted at line 1 to prevent method() from being overridden without causing
compile time errors ?

a. final
b. private
c. protected
d. default
e. Hiding cannot be prevented.

20. What is the o/p of following code?

public class test

{
public static void main( String [] args )
{
new test();
}
test()
{
test(2);
}
test(int x)
{
System.out.println(x);
}
}

a. Prints 2
b. Prints 0
c. Does not compile
d. Runtime Exception.
e. None of the above.

21. Which of the following are not legal identifiers ?

a. String #baby;
b. char c123;
c. Byte $wombat;
d. Long long;
e. Short ~english;
[Type here]

22. Identify the super class of all errors and Exceptions in the Java language.

a. Exception
b. Error
c. Throwable
d. Runnable

23. Which one of the following options is a collection of related classes and Interfaces providing access protection
and name space management in java ?

a. Class
b. Package
c. Interface
d. Collection

24.
class test
{
public static void main(String[] args)
{
test inst_test = new test();
String pig[][] = { {"one little piggy"}, {"two little piggies"}, {"three little piggies"} };
for ( Object []oink : pig )
{
for ( Object piggy : oink )
{
System.out.println(piggy);
}
}
}
}

a.one little piggy two little piggies three little piggies


b. Compile Error incompatible types.
c. Prints nothing
d. Runtime NullpointerException

25. ______ interface provides methods for retrieving data returned by an SQL statement.

a. Driver
b. ResultSet
c. Statement
d. Connection
[Type here]

26. The JDBC drivers can be loaded using

a. forDriver()
b. for()
c. forName()
d. forLoad()

27. JDBC-ODBC Bridge Plus ODBC Driver is used for connecting databases through

a. System DSN
b. Driver Manager
c. JDBC
d. Ms-Access

28. The statement rs.getString(2); , will fetch data in second field of a table in database.
TRUE /FALSE

29. ________ is the capability of a method to do different things based on the object that is acting upon it.

a. Encapsulation
b. Abstraction
c. Put()
d. Polymorphism

30. Select the Odd one out.

a. Private
b. Final
c. Public
d. Default

31. Any exception that is thrown out of a method must be specified by a ________ clause.

a. Catch
b. Finally
c. Throw
d. Throws

32. _____ represents a string that can be modified ?

a. String [];
[Type here]

b. String
c. String [] []
d. StringBuffer

33. ______ has an interpreter component that enables communication between Java byte code and a computer’s
operating system

a. JDK
b. JVM
c. Java Compiler
d. Just InTime Compiler

34. The _____ keyword allows the main() method to be called, without needing to create an instance of the class.

a. abstract
b. implements
c. synchronize
d. static

35. When you invoke repaint() method for a Component , the AWT package calls which component method ?

a. repaint()
b. run()
c. paint()
d. draw()

36. What is the result of following code?

import java.util.*;
class LinkedListDemo {
public static void main(String args[])
{
LinkedList l=new LinkedList();
l.add("The Firm");
l.add("A Time to Kill");
l.add("Rage of Angels");
l.add("The Best Laid Plans");
}
}

a. Compile Error
b. Creates instance of Linked List
c. Creates nodes of Linked List
d. RunTime Error
[Type here]

37.The 2 methods for creating Threads are _______ & ________ .

38.An __________ method is a method that don’t have a method body.

a. Final
b. Private
c. Abstract
d. Interface

39. Given that ex is a class that extends from Exception

public void blah() throws IOException , ex


{
throw new ex();
throw new IOException();
}

a. Compile error unreachable code


b. Compile error: cant throw two exceptions at the same time
c. Compile error: both Exceptions need to be handled in try catch block
d. Runtime error
e. No errors. Compiles fine without warnings

40. What is the result of the code ?

class bike
{
}
class arr extends bike{
public static void main(String[] args) {
arr[] a1=new arr[2];
bike[] a2;
a2=a1; //3
arr[] a3;
a3=a1; //5
}}

a. compile time error at line 3


[Type here]

b. compile time error at line 5

c. Runtime exception

d. The code runs fine

e. None of the above

41. Singleton classes can be implemented in following way(S):


a. Early Initialization
b. Lazy Initialization
c. Late Initialization
d. Live Initialization

42. When Subclass type refers to the object of Parent class, it is known as _______________ .
a. Up casting
b. Inheritance
c. Object
d. Down casting

43. An _________ is a collection of abstract methods.


a. Interface
b. Class
c. Sub Class
d. Singleton Class

44. In Java ________ interface is used to order the objects of user-defined class.

a. Comparable

b. CompareTo

c. Sort

d. Collections

45. List is used for collection of elements with duplicates. TRUE /FALSE

46.___________ is a mechanism of converting the state of an object into a byte stream.

a. Serialization

b. Reflection

c. Streaming
[Type here]

d. Parsing

47. Select the correct statement to create a Scrollable ResultSet:

a. Statement stmt=con.CreateStatement(param1, param2);

b. Statement stmt=con.CreateStatement();

c. Statement stmt=con.CreateStatement(param1);

d. Connection con =stmt.CreateStatement(param1, param2);

48. The _________ method of Connection interface returns the instance of CallableStatement.

a. preparedCall()

b. CallMethod()

c. prepareCall()

d. connectioanCall()

49. A class that is defined with a parameter of a type is called a _____ class.

a. Instance

b. Generic

c. Type class

d. Base Parameter Class

50. _________ performs iteration in either direction, modify the list during iteration, and obtain the iterator's
current position in the list.

a. Iterator

b. ListIterator

c. Foreach

d. For

********************
[Type here]

***

You might also like