MCQ Java
MCQ Java
MCQ Java
(Optional) The Question Itself Correct answer Wrong answer Wrong answer Wrong answer Wrong answer Marks
CoreJava- Consider the following listed items: A-II, B-III, C-I A-III, B-I, C-II A-I, B-II, C-III A-II, B-I, C-III 2
AccessSpecifiers-001 A. Employee() { }
B. public Employee() { }
C. private Employee() { }
CoreJava- Which of the following statement is true regarding Parameterized constructors Parameterized Parameterized Parameterized 2
AccessSpecifiers-003 parameterized constructors? can accept variable constructors constructors constructors
arguments as their cannot accept its cannot accept cannot call the
parameters same class type final arguments default
as parameter as parameters constructor
CoreJava- Consider the following code: The this() call should be the Compiles Default The this can be 2
AccessSpecifiers-004 first statement in the successfully constructors used only for
class Student { constructor without any error cannot be called accessing the
private String name; from member data and
parameterized member methods,
public Student() { } constructors not constructors
public Student(String name) {
this.name = name;
this();
}
}
CoreJava- Which of the following statements are true regarding var- 1,2 2,3 3,4 4,5 2,5 2
AccessSpecifiers-008 args?
CoreJava- Consider the following listed items: A-II, B-III, C-I A-II, B-I, C-III A-I, B-III, C-II A-I, B-II, C-III 2
AccessSpecifiers-009 A. Differing by Signatures
B. Code that executes before main() method
C. Code that executes before constructor
CoreJava- Consider the following code: Both the length() methods Both the length() Overloaded Overloaded 2
AccessSpecifiers-012 are duplicated methods methods are methods cannot methods should
public class TestOverloading { overloaded start with a be declared as
int _length(String s) { methods special character public
return s.length(); like '_'
}
float _length(String s) {
return (float) s.length();
}
}
CoreJava- Which of the following statement is true regarding access Protected level access is Private level Public is Package level 2
AccessSpecifiers-015 specifiers? only for members, not for access is applicable for access is only for
classes applicable for local variables members, not for
both classes and classes
its members
CoreJava- Consider the following code: 3,4 1,2 2,3 4,5 1,5 2
AccessSpecifiers-016
class One {
private void method() {
System.out.println("method in One");
}
}
Normal Version
HiHelloWelcomeBye
Normal Version
100
Normal Version
100
CoreJava- Consider the following code: Compile time error 'The Built-out Runtime Error Built-out method: 3
AccessSpecifiers-020 method method() in the method: Hello 'Unable to resolve Hello
class MethodProvider { type MethodProvider is not Built-in method: the method Built-in method:
public String message; applicable for the Hello method(String)' null
void method() { arguments (String)'
System.out.println("Built-in method:" + message);
}
}
ABC
123
10.020.030.0
CoreJava- Consider the following code: Object o Object o[] Integer id, String Object id, Object 3
AccessSpecifiers-022 name, Double name, Object
class Student { salary salary
private Integer id;
private String name;
private Double salary;
public Student() { }
public Student(/* CODE */) {
for(int i=0; i<p.length; i++){
switch(i) {
case 0: id = (Integer) p[i]; break;
case 1: name = (String) p[i]; break;
case 2: salary = (Double) p[i]; break;
}
}
}
@Override
public String toString() {
return "Id:" + id + "\n" +
"Name:" + name + "\n" +
"Salary:" + salary;
}
}
public Student() { }
public Student(Integer id, String name, Double salary)
{ this.id = id;
this.name = name;
this.salary = salary;
}
public Student(Student s)
{ /* CODE */
}
}
public Student() { }
public Student(Integer id, String name, Double salary)
{ this.id = id;
this.name = name;
this.salary = salary;
}
public void setStudentDetails(Student s) {
System.out.println("Setting Student Details");
this(s.id, s.name, s.salary);
}
public String getStudentDetails() {
String result = "";
result += "Id:" + id + "\n" +
"Name:" + name + "\n" +
"Salary:" + salary;
return result;
}
}
SubClass() { }
SubClass(int param1, int param2, int param3, int
param4) {
/* CODE */
this.param3 = param3;
this.param4 = param4;
}
}
Employee() { }
Employee(Integer id, String name, Double salary) {
this.id = id;
this.name = name;
this.salary = salary;
}
@Override
public String toString() {
return "Id:" + this.id + "\n" +
"Name:" + this.name + "\n" +
"Salary:" + this.salary;
}
}
/* CODE */
import me.you.YourSharedProperty;
package me.you;
import me.MySharedProperty;
1) CODE 1 - static
CODE 2 - static
CODE 3 - new SubClass().method2();
CODE 4 - new SuperClass().method1();
2) CODE 1 - No Code
CODE 2 - No Code
CODE 3 - new SubClass().method2();
CODE 4 - new SuperClass().method1();
CoreJava- Consider the following code: Class Not Found 10 11 Class Not Found 3
AccessSpecifiers-030 10 11
package com.teststatic;
class Static {
static int i=10;
static {
try {
Class.forName("com.teststatic.Static");
i++;
} catch(ClassNotFoundException cnfe) {
System.out.println("Class Not Found");
}
}
}
CoreJava- Consider the following code: 100 Class Not Found Class Not Found 102 3
AccessSpecifiers-031 100 Class Not Found
package com.testinstance; 100
class Instance {
static int i=100;
{
try {
Class.forName("com.testinstance.Instance");
i++;
} catch(ClassNotFoundException cnfe) {
System.out.println("Class Not Found");
}
}
}
CoreJava- Consider the following code: 1002 Class Not Found 1001 Class Not Found 3
AccessSpecifiers-032 1001 Class Not Found
package com.testinstance; 1002
class Instance {
static int i=1000;
{
try {
Class.forName("com.testinstance.Instance");
i++;
} catch(Exception e) {
System.out.println("Exception");
}
}
}
Class.forName("com.testinstance.Instance").newInstanc
e();
}catch(Exception e) {
System.out.println("Exception");
}
System.out.println(new Instance().i);
}
CoreJava- Consider the following code: 40 20 10 Class Not Found 3
AccessSpecifiers-033 Class Not Found
package com.test; 20
class StaticInstance {
static int i = 10;
static {
i+=10;
try {
Class.forName("com.test.StaticInstance").newInstance();
} catch(Exception e) {
System.out.println("Class Not Found");
}
}
{
i+=10;
}
}
Class.forName("com.test.StaticInstance").newInstance();
} catch(Exception e) {
CoreJava- Consider the following code: 110 110 Compile time Compile time error 110 3
AccessSpecifiers-034 10 110 error 'too many 'Ambiguous 110
package com.test; 10 10 static blocks' declaration of i' 110
class TwoStatic {
static int i = 10;
static {
int i = 100;
i += StaticInstance.i;
System.out.println(i);
}
static {
System.out.println(i);
}
}
1) '@Deprecated
2) '@Override
3) '@SuppressWarnings
4) '@Documented
5) '@Target
CoreJava-Annotations- Which of the following option gives the super type of all java.lang.annotation.Annot java.lang.Annotat java.annotation.A There is no super 1
003 Annotation types? ation ion nnotation type for an
Annotation type.
An Annotation
type is just an
interface defintion
CoreJava-Annotations- Which of the following option gives the Java Language Try-Catch Blocks Methods Instance Local Variables Classes 1
004 Element that cannot be annotated? Variables
CoreJava-Annotations- Which of the following option gives the value of the ElementType.TYPE ElementType.AN ElementType.CLA ElementType.INTE ElementType.ENU 1
005 ElementType that controls an annotation type to be NOTATION_TYPE SS RFACE M
applicable only for classes, interfaces, annotation types
and enums?
CoreJava-Annotations- Which of the following options give the marker 3,4,5 1,2,3 2,3,4 1,4,5 2,3,5 1
006 annotations among built-in annotations in Java?
1) '@Target
2) '@Retention
3) '@Override
4) '@Deprecated
5) '@Inherited
CoreJava-Annotations- Which of the following is true about Annotations? An annotation is a special An annotation Annotation Annotations can 1
007 kind of modifier can be declared methods allow replace interfaces
at public, private, wrapper types as in Java
protected and its return types,
package access as an alternative
levels to its equivalent
primitive types
CoreJava-Annotations- Which of the following Java language element allows Annotations Interfaces Enums Classes 1
008 method declarations to be assigned to compile-time
constants?
CoreJava-Annotations- Which of the following are true regarding Annotation? 2,3,5 1,2,3 2,3,4 3,4,5 2,4,5 2
009
1) Annotation refers to data in a Java Program
2) Annotation refers to metadata in a Java Program
3) Annotations can be embedded into class files
4) Annotations are not retrievable at run-time
5) Annotations can replace XML configurations
CoreJava-Annotations- Which of the following option gives the Built-in @Retention @Target @Accessible @Runtime @Reflexive 2
010 annotation, that controls the class level and runtime
accessibility of an User defined annotation?
CoreJava-Annotations- Which of the following option gives the Built-in @Target @Element @ElementType @Use 2
011 annotation, that controls the use of an User defined
annotation with various Java Language Elements?
CoreJava-Annotations- Consider the following code: 2,3 1,2 3,4 4,5 1,5 2
012
public @interface Demo {
public String value();
}
1) '@Demo
class MyClass { }
2) '@Demo(value = "Test")
class MyClass { }
3) '@Demo("Test")
class MyClass { }
4) '@Demo(value="Test");
class MyClass { }
5) '@Demo("Test");
class MyClass { }
CoreJava-Annotations- Which of the following statements are true regarding the 1,4 2,3 3,4 4,5 2,5 2
013 usage of @Inherited annotation type?
CoreJava-Annotations- Which of the following statements are true about 1,4 2,3 3,4 4,5 1,5 2
014 @Override annotation?
CoreJava-Annotations- Which of the following is true regarding the use of The @Override can be used The @Override The @Override The @Override 2
015 @Override? only while overriding a can be used only can be used only can be used only
method in the super class while overriding while overriding while overriding
a method an abstract any built-in
declared in an method in the functions of Java
interface super class Core API
CoreJava-Collections- Consider the following Statements: Both the Statements A and Statement B is Statement A is Both the 2
001 B are false True and True and Statements A and
A: WeakHashMap is synchronized. Statement A is Statement B is B are true
B: All Set implementation Rejects Duplicates but is false false
ordered.
Column A
1) Vector
2) HashSet
3) TreeSet
4) ArrayList
Column B
A) It is not ordered or sorted
B) It compares and stores the data in a sorting order
C) Permits all elements including NULL.
D) It tries to optimize storage management by
maintaining a capacity and a capacity Increment.
CoreJava-Collections- Which of the following option gives the valid collection LinkedList ArrayList Collection List Vector 2
003 implementation class that implements the List interface
and also provides the additional methods to get, add and
remove elements from the head and tail of the list
without specifying an index?
CoreJava-Collections- Which of the following statements give the advantages of 2,4 1,2 2,3 4,5 1,5 2
004 using a Generic Collection?
1) Thread Safety
2) Type Safety
3) JVM Safety
4) Automatic Type Casting
5) Quicker Garbage Collection
CoreJava-Collections- Which of the following statement gives the disadvantage Not compatible with the Forces the user Generic Use of generic 2
005 of Generic Collection? applications developed to mention the collections collections
using JDKs prior to the data type while cannot be removes thread
version 1.5 declaring and iterated using safety for the
creating Iterator, only collection class
instances of foreach being used
Generic statement works
Collections with Generic
Collections
CoreJava-Collections- Consider the following listings: 1-A, 2-C, 3-E 1-A and B, 2-C, 3- 1-A and B, 2-C, 3- 1-A, 2-C, 3-D 2
006 Column A: E D
1. Denotes a family of subtypes of type Type
2. Denotes a family of supertypes of type Type
3. Denotes the set of all types or ANY
Column B:
A. ? extends Type
B. ? implements Type
C. ? super Type
D. *
E. ?
CoreJava-Collections- Consider the following partial code: Creates a Date object with Creates a Date Creates a Date Creates a Date 2
009 current date and time as object with '01- object with 0 as object with
java.util.Date date = new java.util.Date(); default value 01-1970 12:00:00 default value current date alone
AM' as default as default value
Which of the following statement is true regarding the value
above partial code?
CoreJava-Collections- Consider the following code snippets: B,D A,B B,C D,E A,E 2
010
A. java.sql.Date d = new java.sql.Date();
C. java.util.Calendar cal =
java.util.Calendar.getInstance();
java.util.Date d = cal.getDate();
D. java.util.Calendar cal =
java.util.Calendar.getInstance();
java.util.Date d = cal.getTime();
CoreJava-Collections- Consider the following partial code: for (Iterator<String> for for for 2
011 myListIterator = (<String>Iterator (Iterator<String> (<String>Iterator
for (Iterator myListIterator = myList.iterator(); myList.iterator(); myListIterator = myListIterator = myListIterator =
myListIterator.hasNext(); ) { myListIterator.hasNext(); ) {
myList.iterator(); myList.iterator(); myList.iterator();
String myElement = (String) myListIterator.next(); String myElement = myListIterator.ha myListIterator.Ne myListIterator.has
System.out.println(myElement); myListIterator.next(); sNext(); ) { xt(); ) { String(); ) {
} String String String
System.out.println(myElem myElement = myElement = myElement =
Assume that 'myList' is a java.util.List type object. ent); myListIterator.ne myListIterator.ne myListIterator.nex
} xt(); xt(); t();
Which of the following option gives the code which is
equivalent to the above partial code using Generics? System.out.printl System.out.printl System.out.println
n(myElement); n(myElement); (myElement);
} } }
CoreJava-Collections- Consider the following code: Throws Runtime Exception Compilation error Prints the output Prints the output 2
012 at line no 8 [Green World, 1, [Green World,
01 import java.util.Set; Green Peace] at Green Peace] at
02 import java.util.TreeSet; line no 9 line no 9
03
04 class TestSet {
05 public static void main(String[] args) {
06 Set set = new TreeSet<String>();
07 set.add("Green World");
08 set.add(1);
09 set.add("Green Peace");
10 System.out.println(set);
11 }
12 }
CoreJava-Collections- Consider the following code and predict the output: Runtime error at the line Compilation error Runtime error at Prints the output 2
015 commented as Line 2 at the line the line as
import java.util.*; commented as commented as [Alaska, Fashion]
Line 4 Line 3 [Alaska, Fashion]
public class SetTest{
public static void main(String[] args) {
Set s = new HashSet();
s.add("Alaska"); // Line 1
s.add(new Fashion()); // Line 2
Set t = new TreeSet();
t.add("Alaska"); // Line 3
t.add(new Fashion()); // Line 4
System.out.println(s);
System.out.println(t);
}
}
CoreJava-Collections- Consider the following code: [GSLV, PSLV, Chandrayaan] [GSLV, PSLV, SLV, [GSLV, PSLV, IRS] [GSLV, SLV, 2
018 Chandrayaan] Chandrayaan]
import java.util.*;
CoreJava-Collections- Consider the following scenario: Queue HashSet Stack HashMap ArrayList 3
023
Two Client Systems A and B are connected to a Server.
Client A keeps sending some messages asynchronously to
Client B through the Server. The server keeps track of all
the messages coming from Client A and dispatches it in
the same sequences how it is recevied from Client A. The
messages sent by Client A is delivered to Client B after a
short time delay.
CoreJava-Collections- Consider the following scenario: Iterator Enumerator Enumeration Remover Comparator 3
024
An ArrayList is popluated with the names of all the
employees in a company.
Now the names start with the string "AR" should only be
removed from the list.
CoreJava-Collections- Consider the following scenario: private Map<User, private private private 3
029 Set<Account>> users = null; Map<Account, Map<User, Map<Account,
An online application maintains a list of logged-in users. Set<User>> users List<Account>> List<User>> users
Every user has some set of accounts configured by them, = null; users = null; = null;
but subject to the following conditions:
* The Users list should be unique
* The accounts list also should be unqiue
* With the help of user, the corresponding accounts also
should be accessible
CoreJava-Collections- Consider the following code: 1,3 2,3 3,4 4,5 1,5 3
031 01 import java.util.*;
02
03 public class Convert2Generic {
04 public static void main(String[] args) {
05 List customerList = null;
06 customerList = readCustomers();
07 }
08
09 private static List readCustomers() {
10 // Code to read and return customers data
11
12 }
13 }
14 class Customer {
15 public String customerId;
16 public String customerName;
17 }
class Person { }
class Employee extends Person { }
class Consultant extends Person { }
List<Employee> employees =
new ArrayList<Employee>();
employees.add(new Employee());
employees.add(new Employee());
process(employees);
List<Consultant> consultants =
new ArrayList<Consultant>();
consultants.add(new Consultant());
consultants.add(new Consultant());
process(consultants);
}
CoreJava-Collections- Consider the following Code: Prints: 1 -1 Prints: 1 0 Prints: 2 0 Prints: 2 -1 3
034
import java.util.List; import
java.util.ArrayList; import
java.util.Collections;
public FriendsList() {
/* CODE */
}
public void addFriend(Friend friend) {
// Add friend logic
}
public void removeFriend(String friendName) {
// Remove friend logic
}
}
class Friend {
private String friendName;
public Friend(String friendName) {
this.friendName = friendName;
}
}
CoreJava-Collections- Consider the following partial code: 2,5 1,2 2,3 3,4 3,5 3
040
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;
1) cal.add(Calendar.DAY, 5);
2) cal.roll(Calendar.DAY_OF_MONTH, 5);
3) cal.set(Calendar.DAY, 5);
4) cal.roll(Calendar.DAY, 5);
5) cal.add(Calendar.DAY_OF_MONTH, 5);
CoreJava-Controlflow- Consider the following code snippet: Prints the message the value of i is 0 the value of i is 1 Compilation error Runtime error 2
001 "Finished"
int i=0;
while(i-- >0) {
System.out.println(the value of i is +i);
}
System.out.println(Finished);
1) =
2) ==
3) ++
4) --
5) +
CoreJava-Controlflow- Which of the following listed loop type in Java does not for each loop while loop do ... while loop for loop a loop formed using 2
006 depend on Boolean expression to terminate its if and break
execution?
CoreJava-Controlflow- Consider the following code snippet: 2 4 8 16 32 64 2 4 8 16 32 24816 None of the listed 2
007 options
public static void main(String args[]) {
int N;
N=1;
While(N<=32) {
N= 2*N;
System.out.print(N + " ");
}
}
CoreJava-Controlflow- Which of the following statements are true regarding 1,3,4 2,4,5 1,2,3 2,3,4 3,4,5 2
009 switch-case structure?
CoreJava-Controlflow- Which of the following statements are true regarding if- 2,3 1,2 3,4 4,5 1,4 2
010 else structure and switch-case structure?
CoreJava-Controlflow- Which of the following option is not a valid wrapper type new Character("a"); new Byte("10"); new new new 2
011 object creation? Long("3465"); Integer("637"); Boolean("truth");
CoreJava-Controlflow- Consider the following code: new truth one old truth new truth one old truth 2
012 new truth one new truth two new truth two new truth one
class TestWrapper {
public static void main(String[] args) {
boolean oldTruth = true;
Boolean newTruthOne = new Boolean("true");
Boolean newTruthTwo = new Boolean("true");
System.out.println((oldTruth == newTruthOne) ? "new
truth one" : "old truth");
System.out.println((newTruthOne == newTruthTwo) ?
"new truth two" : "new truth one");
}
CoreJava-Controlflow- Consider the following code snippet: Auto-boxing: 3, Auto- Auto-boxing: 4, Auto-boxing: 1, Auto-boxing: 2, 2
015 Unboxing: 2 Auto-Unboxing: 3 Auto-Unboxing: 0 Auto-Unboxing: 0
Integer i=1411, j=i;
System.out.println(i++);
System.out.println(++j);
CoreJava-Controlflow- Which of the following statements are true about labeled 2,5 1,2 2,3 3,4 1,5 2
018 break?
CoreJava-Controlflow- Consider the following code snippet: 1411 1411 1411 Compile time error Runtime error 2
019 java.lang.Integer java.lang.Number java.lang.Object 'Cannot assign an 'Unable to convert
Object n = 1411; integer value to a long value to
System.out.println(n); Object' Object type'
System.out.println(n.getClass().getName());
CoreJava-Controlflow- Consider the following code: Prints: Keeps on printing Prints: Shows compile 3
022 Save Our Tigers "Save Our Tigers" Save Our Tigers time error that
class SaveOurTigers { Share this infinitely labeled break
public static void main(String args[]) { cannot be used
int count = 1411; with switch
statement
switch(count) {
case 1411: again: {
System.out.println("Save Our Tigers");
break again;
}
default: {
System.out.println("Share this");
break;
}
}
}
1) Prints: 1 2 3
2) Prints: 2 3 4
3) Forms an indefinite loop at line number 5
4) Forms an indefinite loop at line number 6
5) Forms an indefinite loop at line number 7
CoreJava-Controlflow- Consider the following code: Prints: aeTgr Prints: eTgr After printing After printing eTgr 3
029 aeTgr throws throws
class TestWhile2 { StringIndexOutOf StringIndexOutOfB
public static void main(String args[]) { BoundsException oundsException
String roar = "Save Tigers";
int index = 0;
while(index * 2 + 1 < roar.length())
System.out.print(roar.charAt(index++ * 2 + 1));
}
}
CoreJava-Exceptions- Which of the following statement is true regarding the The overriding method When a method The overriding the overriding 2
002 throws declarations for overriden methods? cannot declare additional in the super class methods cannot method cannot re-
exceptions which is not is declared to declare to throw declare the
declared in its super class throw a Checked the Super Class Unchecked
version. Exception, the types of those exceptions, that
overriding exceptions are declared by
method in the declared in the super class
sub class should super class method.
also declare the methods.
same.
CoreJava-Exceptions- Which of the following listed type cannot be caught and None of the listed options java.lang.Excepti java.lang.Error java.lang.Throwabl 2
003 handled using catch block? on e
CoreJava-Exceptions- Which of the following options give the types that 1,3 2,3 3,4 4,5 1,5 2
004 Throwable Constructor can accept?
1) String
2) StringBuffer
3) Throwable
4) Integer
5) Boolean
CoreJava-Exceptions- Which of the following statements are true regarding try- 1,3 1,2 2,3 3,4 1,4 2
005 catch-finally blocks?
CoreJava-Exceptions- Which of the following statements are true regarding try- 2,3,5 1,2,3 2,3,4 3,4,5 1,4,5 2
006 catch-finally?
CoreJava-Exceptions- Which of the following are true regarding implementing 3,4 1,2 2,3 4,5 3,5 2
007 user defined exception mechanisms?
CoreJava-Exceptions- Consider the following code: Prints Compiler time Compile time Run time error 3
011 Exception error error test() method
class MyException extends Throwable { } Userdefined Cannot use does not throw a
exceptions Throwable to Throwable
public class TestThrowable { should extend catch the instance
public static void main(String args[]) { Exception exception
try {
test();
} catch(Throwable ie) {
System.out.println("Exception");
}
}
CoreJava-Exceptions- Consider the following code: Finally Inner Finally Outer Exception Outer Exception Outer Finally Inner 3
015 Exception outer Exception Outer Finally Inner Finally Outer Finally Outer
public class FinallyFinallyFinally { Finally Outer Finally Outer Exception Outer
public static void main(String args[]) {
try {
try {
throw new java.io.IOException();
}
finally { System.out.println("Finally Inner");}
} catch(Exception e){ System.out.println("Exception
Outer"); }
finally { System.out.println("Finally Outer");}
}
}
class Planet {
void revolve() throws PlanetException {
System.out.println("Planet revolves");
}
}
CoreJava-Exceptions- Consider the following code: 1,2,3 2,3,4 3,4,5 1,4,5 1,2,5 3
021
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
class SuperClass {
void method() throws IOException {
System.out.println("Super Class");
}
}
1) java.lang.Error
2) java.io.IOException
3) java.lang.Throwable
4) java.lang.Exception
5) java.sql.SQLException
CoreJava-Exceptions- Consider the following code: 1,2 2,3 3,4 4,5 1,5 3
031
public class HierarchyCommunicator {
public static void main(String args[]) {
try {
communicator1();
} catch(Throwable e) {
System.out.println("ArrayIndexOutOfBounds
caught");
}
}
static void communicator1() throws /* CODE 1 */
{ communicator2(); }
static void communicator2() throws /* CODE 2 */
{ communicator3(); }
static void communicator3() throws /* CODE 3 */ {
throw new ArrayIndexOutOfBoundsException();
}
}
1) CODE 1 - Exception
CODE 2 - RuntimeException
CoreJava-Exceptions- Consider the following code: finally method1 finally method1 finally method1 FileNotFoundExce 3
032 IOException FileNotFoundExc ption
import java.io.IOException; eption finally method1
import java.io.FileNotFoundException;
CoreJava-Exceptions- Consider the following code: Returning from inner try Returning from Returning from Shows compile Shows compile 3
033 Returning from inner finally inner try inner try time error time error
01 public class TestReturnInFinally { Returning from outer finally Returning from 100 'Unreachable code 'Unreachable code
02 public static void main(String args[]) { 300 inner finally at line numbers 11 at line number 15'
03 System.out.println(testMethod()); 200 and 15'
04 }
05 static void testMethod() {
06 try {
07 try {
08 System.out.println("Returning from inner try");
09 return 100;
10 } finally {
11 System.out.println("Returning from inner
finally");
12 return 200;
13 }
14 } finally {
15 System.out.println("Returning from outer
finally");
16 return 300;
17 }
18 }
19 }
CoreJava- Consider the following code snippet: Strong Reference Soft Reference Weak Reference Phantom 2
GarbageCollection- Reference
001
String message = "What Reference Type is this?";
CoreJava- Consider the following code snippet: Only the Garbage testObject.finaliz System.gc(); testObject = null; testObject.delete(); 2
GarbageCollection- Collection System can e();
002
Object testObject = new Object(); destroy an object.
CoreJava- Which of the following statements are true about Weak 1,5 1,2 2,3 3,4 2,4 2
GarbageCollection- Reference?
003
1) Weak References are cleared aggressively
2) Weak References will stay in memory for a while
3) Checked by the garbage collector before throwing
OutOfMemoryError
4) WeakReference is the base class for the other two
references
5) Objects in Weak reference can be processed even
after they become unreachable
CoreJava- Which of the following statements are true about Soft 2,4 1,2 2,3 3,5 4,5 2
GarbageCollection- Reference?
004
1) Soft References are created aggressively
2) Soft References are kept for a while in the memory
3) SoftReference extends WeakReference
4) Soft References can be used for implementing
memory caches
5) Soft References internally keeps a second copy of
every reference it maintains
CoreJava- The garbage collector makes sure that all Soft Reference Weak Reference Phantom Strong Reference 2
GarbageCollection- ______________ objects held by soft references are Reference
005
garbage collected before the VM throws an
OutOfMemoryError.
CoreJava- Which of the following statements are true about finalize 1,5 2,3 3,4 1,4 3,5 2
GarbageCollection- method?
006
1) finalize will always run before an object is garbage
collected
2) finalize may run before or after an object is garbage
collected
3) finalize will run when an object becomes unreachable
4) finalize allows a programmer to free memory allocated
to an object
5) finalize method will be called only once by the garbage
collector
CoreJava- Which of the following happens if an uncaught exception The exception will be The exception The exception will The exception will 2
GarbageCollection- is thrown from during the execution of the finalize() ignored and the garbage will be thrown to be ignored, but be thrown to JVM
007
method of an object? collection (finalization) of JVM and the the garbage and the garbage
that object terminates garbage collection collection
collection (finalization) of (finalization) of
(finalization) of that object will be that object will
that object completed also be completed
terminates
CoreJava- Which of the following statement is true about Phantom Enqueued only when the PhantomReferen Checked by the PhantomReferenc 2
GarbageCollection- References? object is physically ce is also called garbage collector e extends
008
removed as Strong before throwing SoftReference
Reference OutOfMemoryErr
or
CoreJava- Which of the following class is used by WeakReference java.lang.ref.ReferenceQue java.lang.ref.Wea java.lang.ref.Dea java.lang.ref.Queu 2
GarbageCollection- class in order to collect the dead references? ue kReference.Queu dReferences edReferences
009
e
CoreJava- Consider the following code: 1 object 3 objects 2 objects 0 object 3
GarbageCollection-
010
import java.util.*;
class Customer {
private String customerName;
public Customer(String customerName) {
this.customerName = customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
}
firstString.substring(firstString.indexOf(firstString),
firstString.length());
/* CODE */
}
}
CoreJava- Consider the following code: string = null; stringBuffer = stringBuilder = stringBuffer = null; 3
GarbageCollection- null; null; stringBuilder =
013
public class Test { null;
public static void main(String[] args) {
String string = "String";
StringBuffer stringBuffer = new StringBuffer(string);
StringBuilder stringBuilder = new StringBuilder(string);
/* CODE */
}
}
CoreJava- Consider the following code: 2,3 1,2 3,4 1,4 3,5 3
GarbageCollection-
14 public class Island {
Island i;
public void display() {
System.out.println("island");
this.i.display();
}
public static void main(String [] args)
{ Island i2 = new Island();
Island i3 = new Island();
Island i4 = new Island();
i2.i = i3;
i3.i = i4;
i4.i = i2;
i3 = i4 = null;
i2.display(); // CODE
}
}
CoreJava-Inheritance- Consider the following code: Declaration 1,3,4 Declaration 2,4 Declaration 1,2,3 Declaration 2,3,4 1
001
interface Declare {
CoreJava-Inheritance- Consider the following Statements: Both Statements A and B Statement A is Statement A is Both Statements A 1
008 are true false and B is true true and B is false and B are false
Statement A: Anonymous inner class can be created in
initializer or static blocks
Statement B: Anonymous inner class has no constructor
CoreJava-Inheritance- Consider the following code: It will compile but will not It will not It will not compile It will compile and 2
010 class PriceList{ override the CalPrice compile because because of the it is overriding
public float CalPrice( float num ) { method because of the of the different different return
// assumed to have some processing code here different parameter list. input type in the type.
} parameter list.
}
CoreJava-Inheritance- Consider the following code: 100,10 100100 10,10 Compilation error 2
012
public class Base {
protected int count = 100;
public int getCount() {
return count;
}
}
CoreJava-Inheritance- Consider the following statement that represents a class Shyam { private Tree class Shyam class Shyam { class Shyam class Shyam { 2
014 relationship: bestFriend; } implements Tree private extends Tree { } private
{} BestFriend Tree; } Tree<bestFriend> }
Shyam has a best friend who is a Tree:
CoreJava-Inheritance- Consider the following code: Compilation fails TRUE Fred An exception 2
017 occurs at runtime.
public class TestObj {
public static void main(String[] args) {
Object o = new Object() {
public boolean equals(Object obj) {
return TRUE;
}}
System.out.println(o.equals("Fred"));
}}
CoreJava-Inheritance- Consider the following code: 200100100 200100200 Compile time Runtime error at 3
029 error at Line no 1 Line no 1
public class TestParent {
public static void main(String s[]) {
Child c = new Child();
c.print();
Parent p = new Parent();
p.print();
p = c;
p.print(); // Line no 1
}}
class Parent {
static int x = 100;
public static void print() {
System.out.println(x); }
}
class OuterLevel {
String name = "Apple";
class Inner {
String name = "Mango";
class DeepInner {
class DeepestInner {
}
}
1) String[] args
2) String args[]
3) String ..args
4) String args
5) String[] args[]
CoreJava-Introduction- Which of the following methods are not the member of 2,5 1,2 2,3 3,4 3,5 1
002 Object class?
1) getClass()
2) run()
3) hashCode()
4) wait()
5) currentTimeMillis()
CoreJava-Introduction- Which of the following options give the member 3,4 1,2 2,3 3,5 1,5 1
003 methods of Object class, that cannot be overriden?
1) equals()
2) hashCode()
3) wait()
4) notify()
5) clone()
CoreJava-Introduction- Which of the following options give the valid package 1,2,3 2,3,4 3,4,5 1,4,5 2,3,4 1
004 names?
1) dollorpack.$pack.$$pack
2) $$.$$.$$
3) _score.pack.__pack
4) p@ckage.subp@ckage.innerp@ckage
5) .package.subpackage.innerpackage
CoreJava-Introduction- The term 'Java Platform' refers to ________________. Java Runtime Environment Java Java Database Java Debugger 1
005 (JRE) Development Kit Connectivity
(JDK) (JDBC)
CoreJava-Introduction- Which of the following statement gives the use of Holds the location of User Holds the Holds the location Holds the location 1
006 CLASSPATH? Defined classes, packages location of Java of Core Java Class of Java Software
and JARs Extension Library Library (Bootstrap
classes)
com.testpack
1) import com.testpack.TestPack;
2) import com.testpack;
3) import com.testpack.TestPack.*;
4) import static com.testpack.TestPack;
5) import static com.qb2020.TestPack.*;
CoreJava-Introduction- Which of the following are true about packages? 2,3 1,2 3,4 4,5 1,5 2
008
1) Packages can contain only Java Source files
2) Packages can contain both Classes and Interfaces
(Compiled Classes)
3) Packages can contain non-java elements such as
images, xml files etc.
4) Sub packages should be declared as private in order to
deny importing them
5) Class and Interfaces in the sub packages will be
automatically available to the outer packages without
using import statement.
CoreJava-Introduction- Consider the following: 1,2,3 2,3,4 3,4,5 1,4,5 1,2,4 2
009
There is a package structure
1) Format
2) Correct Indentation
3) Generate Getters and Setters
4) Rename
5) Move
CoreJava-Introduction- Which of the following option gives one possible use of Helps the compiler to find To maintain the Helps JVM to find Helps Javadoc to 2
012 the statement 'the name of the public class should match the source file that uniform standard and execute the build the Java
with its file name'? corresponds to a class, classes Documentation
when it does not find a easily
class file while compiling
CoreJava-Introduction- Consider the following code: On compiling and running main() method Throws a runtime Compiler throws a 2
013 the class TestMain, it prints can be called error 'Ambiguous compilation error
public class TestMain { TestMain only by JVM method main()' 'Too many main()
public static void main(String[] args) { one methods'
System.out.println("TestMain"); two
TestMyClass.main(new String[] {"one", "two"});
}
}
CoreJava-Introduction- Which of the following options give the Characteristics of 4,5 1,2 2,3 3,4 1,5 2
014 Java, that made Java popular in Web Development?
1) Object Oriented
2) Interpreted
3) Robust
4) Portable
5) Secure
CoreJava-Introduction- Which of the following statement is true? Classes can be loaded at Classes can be Classes cannot be Only class that is 2
015 Runtime, without actually loaded at loaded at loaded at runtime
referring the class in the Runtime, but the Runtime is the class that
code at compile time. name of the class contains the
with full package main() method
name should be
given in the code
at compile time.
CoreJava-Introduction- Which of the following option gives the correct sequence Java Class Library Packages in the Packages in the User-defined 2
016 in which the Java Virtual Machine searches for a class? Packages in the extension extension extension packages and
directory of JRE / JDK directory of JRE / directory of JRE / libraries
User-defined packages and JDK JDK Java Class Library
libraries User-defined Java Class Library packages in the
packages and User-defined extension
libraries packages and directory of JRE /
Java Class Library libraries JDK
CoreJava-Introduction- Which of the following statements are true regarding 3,4 1,2 2,3 4,5 2,5 2
017 java.lang.Object class?
CoreJava-IO-002 Consider the following scenario: 1,2,3 2,3,4 3,4,5 1,4,5 1,2,5 3
The List of files with the valid file types need to be listed
in custom dialog box.
1) File class
2) FilenameFilter interface
3) FileFilter interface
4) FileReader class
5) FileInputStream class
CoreJava-IO-003 Consider the following scenario: File class FileProperties Properties class System.properites 3
class
A file manager application is being developed in Java.
CoreJava-IO-004 Consider the following scenario: 1,2 2,3 3,4 4,5 1,5 3
1) File class
2) FilenameFilter interface
3) FileSearchFilter interface
4) FileInputStream class
5) FileReader class
CoreJava-IO-005 Consider the following scenario: 2,4,5 1,2,3 2,3,4 1,4,5 1,2,4 3
1) File class
2) FileInputStream class
3) FileReader class
4) InputStreamReader class
5) BufferedReader
CoreJava-IO-006 Consider the following scenario: 2,3 1,2 3,4 4,5 1,5 3
The text files need to be read line by line from the file. In
the same, the lines need to be written line by line to the
file.
CoreJava-IO-007 Consider the following scenario: RandomAccessFile FileReader DataInputStream FileInputStream LookupStream 3
and
A file contains a 10 x 10 matrix containing 100 double FileInputStream
values. All the 100 values are stored in sequential
manner.
CoreJava-IO-009 Consider the following scenario: Task III Task II Task I Task IV Task V 3
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
/* CODE */
import java.io.Externalizable;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public Employee() { }
public Employee(Integer id, String name, Double salary)
{ this.id = id; this.name = name; this.salary = salary; }
public void readExternal(ObjectInput in) throws
IOException, ClassNotFoundException {
this.id = Integer.valueOf(in.readLine());
this.name = in.readLine();
this.salary = Double.valueOf(in.readLine());
}
public void writeExternal(ObjectOutput out) throws
CoreJava-IO-013 Consider the following code: import java.io.Serializable; import import import import 3
java.io.Serializabl java.io.Serializabl java.io.Serializable java.io.Serializable;
import java.io.Serializable; class CardInfo { e; e; ;
public String cardNo; interface CardInfo
class CustomerInfo implements Serializable { public String cvvNo; class CardInfo { class interface CardInfo extends Serializable
public String customerId; } public String CustomerInfo { {
public String customerName; cardNo; implements public String public String
public transient String cardNo; class CustomerInfo extends public String Serializable { cardNo(); cardNo();
public transient String cvvNo; CardInfo implements cvvNo; public String public String public String
} Serializable { } customerId; cvvNo(); cvvNo();
public String customerId; public String } }
When the object of the above class is serialized, all the public String class customerName;
values of the object except cardNo and cvvNo will be customerName; CustomerInfo public volatile class class CustomerInfo
serialized. } implements String cardNo; CustomerInfo implements
Serializable { public volatile implements CardInfo {
Which of the following code gives the alternative way of public String String cvvNo; CardInfo, public String
getting the same functionality as the above code, without customerId; } Serializable { customerId;
using the transient keyword? public String public String public String
customerName; customerId; customerName;
public CardInfo public String public String
cardInfo; customerName; cardNo() { return
} public String null; }
cardNo() { return public String
null; } cvvNo() { return
public String null; }
cvvNo() { return }
null; }
CoreJava-IO-014 Consider the following code: Runtime Error No errors; Runtime Error Compile time error 3
'IllegalArgumentException: program 'IOException: use 'Unhandled
import java.io.FileInputStream; invalid file open mode' compiles and shared more to Exception
import java.io.IOException; executes open the same FileNotFoundExce
import java.io.RandomAccessFile; properly. file more than ption'
Appends the text once'
public class TestRandom1 { "Next Info" at the
public static void main(String[] args) throws end of the file
IOException { 'C:/TestRandom.t
FileInputStream fin = new xt'
FileInputStream("C:/TestRandom.txt");
RandomAccessFile raf = new
RandomAccessFile("C:/TestRandom.txt", "a");
raf.seek(fin.available());
fin.close();
raf.writeBytes("Next Info");
raf.close();
}
}
raf.seek(fin.available());
fin.close();
raf.seek(-10);
int current = (int) raf.getFilePointer();
raf.read(data, current, 7);
System.out.println(new String(data));
raf.close();
}
}
CoreJava-IO-016 Consider the following code: 2,3 1,2 3,4 4,5 1,5 3
import java.io.IOException;
import java.io.RandomAccessFile;
/* CODE */
raf.close();
}
}
1) raf.seek(1024);
2) raf.seek(1023);
raf.writeBytes("A");
3) raf.setLength(1024);
CoreJava-IO-017 Consider the following code: No errors in the program. Throws runtime Throws compile No errors in the 3
Prints 'Sample Data' error while time error program. But fails
import java.io.Serializable; reading the 'Unsupported to Serialize the
import java.io.FileInputStream; object 'Not a Serializable object. So blank
import java.io.FileOutputStream; Serialized Object' object' space is printed
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
1) Type 1 driver
2) Type 2 driver
3) Type 3 driver
4) Type 4 driver
CoreJava-JDBC-002 ____________________ driver follows a three-tiered Type 3 Type 2 Type 1 Type 4 1
architecture.
CoreJava-JDBC-003 Which of the following driver will be most suitable for Type 4 driver Type 2 driver Type 3 driver Type 1 driver 1
those Java Client Applications that run on different
operating systems but need to connect to a centralized
database server?
CoreJava-JDBC-004 Which of the following option gives the return value of -1 1 0 null 1
getUpdateCount(), when the last result is a ResultSet?
CoreJava-JDBC-005 Which of the following options give new features added 2,4,5 1,2,3 2,3,4 1,4,5 1,3,4 1
in JDBC 2.0?
1) DatabaseMetaData
2) Scrollable ResultSets
3) ResultSetMetaData
4) Batch Updates
5) Programmatic inserts, deletes and updates
CoreJava-JDBC-006 Which of the following option gives the valid method to getMetaData() getResultSetMet getMetaInfo() getResultSetMetaI 1
get the ResultSetMetaData from a ResultSet object? aData() nfo()
CoreJava-JDBC-007 Which of the following option gives the valid method to getMetaData() getDatabaseMet getDBMetaData() getDatabaseMetaI 1
get the DatabaseMetaData from a Connection object? aData() nfo()
CoreJava-JDBC-008 Which of the following listed Class / Interface acutally Driver DriverManager Connection ResultSet 2
establishes the connection to the database using the
given Connection URL String?
CoreJava-JDBC-009 Which of the following listed option gives the valid type java.sql.Timestamp java.sql.Date java.sql.Time java.util.Date 2
of object to store a date and time combination using
JDBC API?
CoreJava-JDBC-010 Which of the following options give the valid methods 2,3 1,2 3,4 4,5 1,5 2
that can be used for executing DDL statements?
1) executeQuery()
2) executeUpdate()
3) execute()
4) executeDDL()
5) executeResult()
CoreJava-JDBC-011 The getPrimaryKeys() method is in which of the following DatabaseMetaData ResultSetMetaDa ResultSet RowSet 2
listed interface? ta
CoreJava-JDBC-012 Which of following statement is true regarding All OUT parameteres must All IN All INOUT No registration is 2
parameter usage in CallableStatement? be registered with parameteres parameteres required for any
CallableStatement object must be must be type of parameter
prior to the execution registered with registered with
CallableStatemen CallableStatemen
t object prior to t object prior to
the execution the execution
CoreJava-JDBC-013 Which of the following option gives the default CONCUR_READ_ONLY CONCUR_UPDAT CONCUR_HOLDA No concurrency is 2
Concurrency of a ResultSet? ABLE BLE associated by
default
CoreJava-JDBC-014 Which of the following option gives the valid way to pass The updater methods are The setter The register The values should 2
the values, while inserting a row using ResultSet? used to set the values for methods are methods are used be passed as
the new row used to set the to set the values parameters to the
values for the for the new row insertRow()
new row method
CoreJava-JDBC-015 Which of the following options are valid sub classes of 1,4 2,3 1,3 3.5 4,5 2
java.util.Date class?
1) java.sql.Time
2) java.sql.ShortDate
3) java.sql.DateTime
4) java.sql.Timestamp
5) java.sql.LongDate
CoreJava-JDBC-016 Which of the following option is a valid interface that DatabaseMetaData ResultSetMetaDa Connection Driver 2
gives the information about the Tables, Views, Stored ta
Procedures and Other database objects in a Database?
CoreJava-JDBC-017 Which of the following statement is tue for an active Starts a new Transaction Starts a new Executes all SQL There is no 2
Connection object for which the auto-commit feature is for every SQL statement Transaction and Statements relation between
set to true? that are executed under executes all the without creating transactions and
that connection. SQL statements, any transaction auto-commit
under that single feature
transaction
CoreJava-JDBC-018 Consider the following code snippet: 3,5 1,2 2,3 3,4 4,5 2
static {
try {
Class.forName("oracle.jdbc.OracleDriver");
} catch(ClassNotFoundException cnfe) {
System.out.println("Driver not found");
}
}
CoreJava-JDBC-023 Which of the following will be the output when a getter The value of the first Throws an Returns an Object There cannot be 2
method is called with a column name and the ResultSet matching column will be SQLException array that more than one
has several columns with the same name? returned stating the error contains the column with the
values of all same name in a
matching Query as well as in
columns the ResultSet
CoreJava-JDBC-024 Which of the following option gives the status of a The ResultSet object is The ResultSet The ResultSet The data in 2
ResultSet object, when the Statement object that automatically closed object remains as object gets ResultSet object
generated it is re-executed? disconnected updated with the becomes Read-
ResultSet with latest changes in only
the previous the data
results
CoreJava-JDBC-025 Consider the following code snippet: SQLException is thrown at SQLException is SQLException is PreparedStatemen 2
the line number 3 thrown at the thrown only at t cannot detect
1 String sql = "select sample_pk, sample_data from line number 2 the time of the non-existence
sample3" processing the of table
2 PreparedStatement ps = c.prepareStatement(sql); ResultSet object
3 ResultSet rs = ps.executeQuery(); rs
CoreJava-JDBC-026 Which of the following statements give the various points 1,3,4 1,2,3 3,4,5 1,3,5 2,3,4 2
at which the commit occurs, for an active Connection
object for which the auto-commit feature is set to true?
CoreJava-Keywords- Consider the following code: Face value System value Face value Main Value 2
001 System value Main value Main value Face Value
public class Main { Main value Face value System value System Value
public String value="Face value";
public Main() {
value="Main value";
System.out.println(value);
}
{
System.out.println(value);
value="System value";
System.out.println(value);
}
public static void main(String[] args) {
Main n=new Main();
}
}
@Before
public void createOutputFile() {
output = new File(...);
}
@After
public void deleteOutputFile() {
output.delete();
}
@Test
public void testSomethingWithFile() {
...
}
}
CoreJava-Keywords- Consider the following Statements about Operators: B,C,D is true and A is false A,C,D is true and A,B is true and A,B,C,D is true 2
011 B is false C,D is false
A) The instanceof operator can not be applied to an
array.
B) The instanceof operator can be applied to object
reference.
C) The equals method compares content of two objects
D) The == operator tests reference of two objects
CoreJava-Keywords- Consider the following code: Statement C and D are Statements B,C Statement B and Statement A is 2
013 correct and D are correct C are correct correct
Line no 1:public class ValidDeclaration{
Line no 2: public static void main(String args[])
Line no 3: {
Line no 4: byte a=126;
Line no 5: byte b=127;
Line no 6: byte c=129;
Line no 7: int e=3333333333;
Line no 8: }
Line no 9:}
CoreJava-Keywords- Consider the following code: Compile time error at line null,1,a 0,1,a Runtime error at 2
014 no 7 line no 9
1 public class Array2
2 {
3 public static void main(String args[]){
4 int[] myA;
5 myA = new int[2];
6 myA[] myB;
7 myB = new myA[3];
8 myB[0]=a;
9 myB[1]=1;
10 myB[2]=3;
11 System.out.println(myA[0]);
12 System.out.println(myB[1]);
13 System.out.println(myB[0]);
14 }}
CoreJava-Keywords- Consider the following Code: Infinity Runtime Error Compile time Infinity 1.4e99f 3
021 -Infinity error -Infinity 2.4e99f
public class question2 { 3.4E99 Infinity 3.4e99
public static void main(String args[]) {
Float f1 = new Float("1.4e99f");
Float f2 = new Float("-2.4e99f");
Double d1 = new Double("3.4e99");
System.out.println(f1);
System.out.println(f2);
System.out.println(d1);
}
}
class Play{
public static void main (String[] args) {
System.out.println (FootBall.rules);
}}
CoreJava-Keywords- Consider the following code: 10,18 18,10 5,9 Compile time error 3
030 at line no 11
Line No 1:public class DoubleDemoArray {
Line No 2: public static void main (String args[]) {
Line No 3: int array1[] = {1, 2, 3, 4, 5};
Line No 4: int array2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
Line No 5: System.out.println("New Array1 size: " +
doubleArray(array1).length);
Line No 6: System.out.println("New Array2 size: " +
doubleArray(array2).length);
Line No 7: }
Line No 8: private static int[] doubleArray(int original[]) {
Line No 9: int length = original.length;
Line No 10: int newArray[] = new int[length*2];
Line No 11: System.arraycopy(original, 4, newArray, 2,
length-4);
Line No 12: return newArray;
Line No 13: }
Line No 14:}
CoreJava-Keywords- Consider the following code snippet: Runtime error at line 1,2,null Compile time 1,2 3
031 number 5 error at line
Line No:1 public class Array3 { number 4
Line No:2 public static void main(String args[]){
Line No:3 int ia[][] = { {1, 2}, null };
Line No:4 for (int[] ea : ia)
Line No:5 for (int e: ea)
Line No:6 System.out.print(e);
Line No:7 }}
switch(c) {
case Ruppee:
CoreJava-Keywords- Consider the following code snippet: 5,20 20,10 10,20 5,10 3
036
public class checkValues {
Line No 1:static int numOne=20;
Line No 2:int numTwo=10;
Line No 3:public static void main(String argv[]){
Line No 4: int numTwo=5;
Line No 5: checkValues p = new checkValues();
Line No 6: p.changeValue(numTwo);
Line No 7: System.out.println(numTwo);
Line No 8: System.out.println(numOne);
Line No 9: }
Line No 10: public void changeValue(int numOne){
Line No 11: numTwo=numOne*2;
Line No 12: numOne=numOne*2;
Line No 13: }
Line No 14:}
CoreJava-Keywords- Consider the following code: Garden status is too many Garden status is Garden status is Error in line 3
037 Flowers Garden limit on Flowers count OK number 6
Line No 1:class GardenFlower { the edge
Line No 2:public static void main(String [] args) {
Line No 3:int numOfFlowers=20;
Line No 4:int sizeOfGarden = 10;
Line No 5:sizeOfGarden=sizeOfGarden<<8;
Line No 6:String status = (numOfFlowers<4)?"Flowers
count OK"
::(sizeOfGarden < 8)? "Garden limit on the edge"
:"too many Flowers";
Line No 7:System.out.println("Garden status is " +
status);
Line No 8:}
Line No 9:}
1) append(boolean b)
2) append(byte b)
3) append(short s)
4) append(int i)
5) append(long l)
CoreJava-Strings-002 Consider the following code snippet: 1634 1632 1616 1734 1
CoreJava-Strings-003 Which of the following statement gives the significance Comparing memory Comparing Comparing object Comparing 1
of overriding equals() method in user defined classes? references of two objects
content of two Ids of two objects creation time of
objects two objects
CoreJava-Strings-004 Which of the following statement gives the significance Ensuring uniqueness of the Ensuring the Ensuring the Ensuring the 1
of overriding hashCode() method in user defined classes? objects being created memory object creation objects added to
allocation for the itself JVM's Object pool
objects being
created
CoreJava-Strings-005 Consider the following code snippet: Line 1 Line 2 Line 3 None of the given 1
line uses JVM's
1 String thirdBinded = "BINDED"; Object Pool
2 String bindedString = new String("Binded");
3 String secondBinded = bindedString.toUpperCase();
CoreJava-Strings-006 Which of the following are NOT a default delimiter of 1,4 2,3 3,4 4,5 1,5 1
StringTokenizer class?
1) , (comma)
2) \t (tab)
3) \n (new line)
4) ; (semi colon)
5) \f (form feed)
CoreJava-Strings-007 Which of the following option gives the name of the NumberFormatException IllegalArgumentE ParseException ArithmeticExcepti 1
Exception which is thrown when a String with Non- xception on
Numeric value is parsed with Integer.valueOf() method?
CoreJava-Strings-008 Which of the following options give the member 2,4 1,2 3,4 4,5 3,5 1
methods of String class that creates new String object?
1) toString()
2) concat()
3) startsWith()
4) trim()
5) endsWith()
CoreJava-Strings-009 Which of the following options give the methods that are 2,4 1,2 3,4 3,5 1,5 1
not member of String class?
1) length()
2) capacity()
3) trim()
4) delete()
5) replace()
CoreJava-Strings-010 Which of the following option gives the member method toString() concat() replace() substring() 2
of String class that does not create a new String object?
CoreJava-Strings-011 Which of the following option is the member method of intern() join() trim() toString() 2
String class, that adds the String object to the JVM's
Object Pool?
CoreJava-Strings-012 Consider the following code snippets: Code Snippet 1 uses more Code Snippet 2 Both the Code The usage of 2
JVM memory than Code uses more JVM Snippets uses JVM's memory
Code Snippet 1: Snippet 2 for storage memory than same amount of differs from JVM
String part1 = new String("Thought"); Code Snippet 1 memory implementation
String part2 = new String("Green"); for storage
String part3 = new String("World");
String part4 = new String("Green");
String fullString = part1 + " is " + part2 + ", so the " +
part3 + " is " + part4;
Code Snippet 2:
String part1 = "Thought";
String part2 = "Green";
String part3 = "World";
String part4 = "Green";
String fullString = part1 + " is " + part2 + ", so the " +
part3 + " is " + part4;
CoreJava-Strings-015 Consider the following code snippet: Prints false Throws Throws Prints null 2
ParseException IllegalArgumentEx
1 String truth = "null"; at line 2 ception at line 2
2 Boolean truthValue = Boolean.valueOf(truth);
3 System.out.println(truthValue);
CoreJava-Strings-017 Which of the following option gives the name of the consistency symmetry transitivity reflexivity 2
property that builds the equivalence relation of equals()
method of an Object, that directly depends on the output
of its hashCode() method?
CoreJava-Strings-018 Which of the following statement gives the exact There is no connection The equals() There is no The equals() 2
relationship between the equals() method and between equals() method method connection method uses an
hashCode() method in the Object class? and hashCode() method in compares the between equals() object comparison
the Object class. The hash code of method and algorithm which
equals() simply compares current object hashCode() takes two
only the memory and object to be method in the different hash
references of current compared, by Object class. It codes and
object and object to be calling simply compares evaluates to either
compared using == hashCode() only the content true or false. The
operator. method and of both the object same is returned
returns true if by just calling by equals()
their hash code equals() method method.
matches, and on the current
false otherwise. object by passing
the object to be
compared.
CoreJava-Strings-019 Which of the following statement is TRUE regarding Both the methods equals() Either equals() or Overriding of Overriding of 2
overriding equals() and hashCode() methods? and hashCode() has to be hashCode() hashCode() equals() method is
overridden at the same method can be method is not not required. The
time overriden leaving required. The implementation of
the other as implementation equals() method in
optional of hashCode() the Object class
method in the itself will serve all
Object class itself the purposes
will serve all the
purposes
CoreJava-Strings-020 Consider the following code snippet: PeaWithPlay PlayWithNuts WithPeaNuts PlayWithPea 3
String greenWorld =
"The World is Green, so is the Thought";
if(greenWorld.substring(
greenWorld.indexOf("Th"),
greenWorld.lastIndexOf("is")
).startsWith("o")) {
System.out.println(greenWorld.substring(
greenWorld.indexOf("Thought")
));
} else {
System.out.println(greenWorld.substring(
0, greenWorld.indexOf("Thought")
));
}
1 int count = 0;
2 String thought = "This\t\\tis intentionally\n\n made
tough";
3 StringTokenizer tokenizer = new
StringTokenizer(thought);
4
for(count=0;tokenizer.hasMoreTokens();tokenizer.nextT
oken("t"), count++);
5 System.out.println(count);
CoreJava-Strings-028 Consider the following code: public int hashCode() { public int public int public int 3
return hashCode() { hashCode() { hashCode() {
public class World { name.hashCode(); return (int) return return
private String name; } System.currentTi super.hashCode() super.hashCode()
meMillis(); ; +
public World() { } } } name.hashCode();
public World(String name) { }
this.name = name;
}
}
CoreJava-Strings-029 Consider the following code: public int hashCode() { public int public int public int public int 3
return hashCode() { hashCode() { hashCode() { hashCode() {
public class GeoCode { longitude.hashCode() + return return return 1000+;
private Double longitude; latitude.hashCode(); super.hashCode() super.hashCode() longitude.hashCod }
private Double latitude; } + 1000; ; e() +
} }
public GeoCode() { } latitude.hashCode(
public GeoCode(Double longitude, Double latitude) { )+
this.longitude = longitude;
this.latitude = latitude; super.hashCode();
} }
}
CoreJava-Threads- Which of the following option gives the name of the wait() notify() notifyAll() sleep() 2
003 method that informs the current thread to leave the
control of the monitor?
CoreJava-Threads- Consider the following Statements: Statement A and B both are Statement B is Statement A and Statement A is 2
004 true true and A is B both are false true and B is false
Statement A: false
wait, notify and notifyAll methods are not called on
Thread, they are called on Object
Statement B:
These methods can only be called from synchronized
code, or an IllegalMonitorStateException will be thrown.
CoreJava-Threads- Which of the following statements are true regarding 2,5 1,2 2,3 3,4 4,5 2
005 threads and classes?
CoreJava-Threads- Consider the following statements: Statement A and B both are Statement B is Statement A and Statement A is 2
008 true true and A is B both are false true and B is false
Statement A: The priority of a thread can be set by using false
the setPriority() method in the Thread class.
Statement B: The priority of a thread can be set by
passing the priority as a parameter to the constructor of
the thread.
1) String name=Thread.currentThread().getName();
2) String name=this.currentThread().getName();
3) String
name=Thread.getInstance().currentThread().getName();
CoreJava-Threads- Consider the following code: Prints I am RunningThread Compiles RunTime error Prints I am 3
010 infinitely. successfully but RunningThread
public class RunningThread implements Runnable generates no Three Times
{ output
public void run()
{
while(true)
{
System.out.println("I am RunningThread");
}
}
public static void main(String args[])
{
RunningThread nt1 = new RunningThread();
RunningThread nt2 = new RunningThread();
RunningThread nt3 = new RunningThread();
nt1.run();
nt2.run();
nt3.run();
}
}
}catch(InterruptedException e)
{
e.printStactTrace();
}
}
}
}
s.go();
}
public void go(){
//Line no 1{code to be replaced here}
}
public void run(){
System.out.println("swim");
}
}
}
catch(InterruptedException e){
System.out.print("3");
}
}
System.out.print("4");
}
}
CoreJava-Threads- Consider the following statements: Both Statement A and B are Statement A is Both Statements Statement A is 3
017 False False and B is A and B are True True and B is False
Statement A: IllegalThreadStateException is a Checked True
Exception
Statement B: InterruptedException is UnChecked
Exception
Which of following are valid events that can occur for the
above scenario to happen?
CoreJava-Threads- Consider the following code: Clean compile but no A run time error Clean compile A compile time 3
019 output at runtime indicating that no and at run time error indicating
public class Test extends Thread{ run method is the values 0 to 9 that no run
public static void main(String argv[]){ defined for the are printed out method is defined
Test b = new Test(); Thread class for the Thread
b.run(); class
}
public void start(){
for (int i = 0; i <10; i++){
System.out.println("Value of i = " + i);
}
}
}
class Charlie
{
public synchronized void doIt()
{
try{
wait(); //LINE 1
System.out.println("done");}
catch(Exception e) { e.printStackTrace();}
}
}
}
}
}
}
}
}}
System.out.println(i);
}
CoreJava-Threads- Consider the following code: Compilation Error at Line helloworld Compilation Error worldhello 3
031 no 2 at Line no 1
public class A extends Thread {
public void run() {
yield();//Line no 1
System.out.println("world");
}
1) Prints: [T1,A][T2,B]
2) Prints: [T1,B][T2,B]
CoreJava-Threads- Consider the following code: Prints CAT Six times and Prints CAT Three Prints CAT Six Prints CAT five 3
033 throws a Runtime times and throws times times and throws
class FirstThread extends Thread { Exception a Runtime a Runtime
public static void main(String [] args) { exception Exception
FirstThread t = new FirstThread();
t.setName("First");
Statement A:
If execution of the block completes normally, then the
lock is released
Statement B:
If execution of the block completes abruptly, then the
lock is released
CoreJava-Threads- Which of the following statements are true regarding 2,4 1,2 2,3 3,4 3,5 3
035 threads?
interface MyRunnable2 {
public abstract void run();
}
CoreJava-Threads- Consider the following code: new Thread(new new Thread(new new Thread(new new Thread(new This cannot be 3
038 RunnableTask()).start(); Task()).start(); Runnable(new Runnable(new done, the class Task
class Task { Task())).start(); RunnableTask())).s should implement
public void run() { tart(); Runnable
System.out.println("Task started");
try {
Thread.currentThread().sleep(2000);
}catch(InterruptedException ie) {
System.out.println("Thread interrupted");
}
System.out.println("Task completed");
}
}
CoreJava-Updations in Which of the following option gives the newly added JDBC 4.0 Annotations Var-args Generics Iterable interface 1
SDK-005 feature to Java SE 6? added as super
interface for
java.util.Collection
CoreJava-Updations in Which of the following option gives the name of the new StAX JAX DOM SAtX SAX 1
SDK-006 type of parser added to the XML API, in JDK 1.6?
CoreJava-Updations in Which of the following option gives the name of the TreeSet HashSet NavigableHashSet NavigableTreeSet 1
SDK-007 Collection implementation class that implements the
newly introduced NavigableSet interface in JDK 1.6?
CoreJava-Updations in Which of the following option gives the name of the java.util.spi java.util.concurre java.util.logging java.util.regex 1
SDK-008 package which is newly added to Java SE 6? nt
CoreJava-Updations in Which of the following option gives the name of the ArrayDeque Deque LinkedDeque BlockingDeque 1
SDK-009 concrete implementation class, which is newly added to
the collection framework in JDK 1.6?