Java MCQ
Java MCQ
Core Java
Post Training Assessment
a. 000
b. ArrayIndexoutOfBoundsException
c. NullPointerException
d. null null null
a. Constructor1
b. Constructor2
[Type here]
c. Constructor1 Constructor2
d. Compiler Error
6. Java Identifiers must start with a letter, dollar sign ($), or underscore (_).
True / False
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); }
9. class A{
static String m(float i) {return "float";}
static String m(double i) {return "double";}
[Type here]
a. prints float,foat
b. prints float,double
c. prints double,double
d. compile time error
e. None of the above
a. abc.length
b. abc.length()
c. abc.size
d. abc.size()
a. this();
b. super.constructor();
c. super();
d. super(Object);
a. Stop()
b. Synchronization
c. Yield()
d. None of these
class Animal
{ void method () throws Exception
{ }
[Type here]
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
{
arr[i] = 0;
}
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.
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);
}
19.
class sup
{
static void method(){System.out.println("Super");} // 1
}
[Type here]
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.
{
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.
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);
}
}
}
}
25. ______ interface provides methods for retrieving data returned by an SQL statement.
a. Driver
b. ResultSet
c. Statement
d. Connection
[Type here]
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
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
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()
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]
a. Final
b. Private
c. Abstract
d. Interface
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
}}
c. Runtime exception
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
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
a. Serialization
b. Reflection
c. Streaming
[Type here]
d. Parsing
b. Statement stmt=con.CreateStatement();
c. Statement stmt=con.CreateStatement(param1);
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
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]
***