Posts which you will also like.

Saturday, June 23, 2012

Java Multiple Choice Questions(MCQ)

This post contains 20 multiple choice question (mcq) in java.Try to solve them for your practice......

1.Given: public class Mule { public static void main(String[] args) { boolean assert = true; if(assert) { System.out.println("assert is true"); } } } Which command-line invocations will compile? 
b.javac -source 1.3
c.javac -source 1.4
d.javac -source 1.5
2) Which exception is thrown by read() method of InputStream class
3)Given: String test = "a1b2c3"; String[] tokens = test.split("\\d"); for(String s: tokens) System.out.print(s + " "); What is the result?
a.a b c
b.1 2 3
d.a1 b2 c3
4)Given: public class Person { private name; public Person(String name) { = name; } public int hashCode() { return 420; } } Which statement is true?
a.The time to find the value from HashMap with a Person key depends on the size of the map.
b.Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.
c.Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.
d.The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.
5)Given: abstract class C1 { public C1() { System.out.print(1); } } class C2 extends C1 { public C2() { System.out.print(2); } } class C3 extends C2 { public C3() { System.out.println(3); } } public class Ctest { public static void main(String[] a) { new C3(); } } What is the result?
6)Given: class One { public One foo() { return this; } } class Two extends One { public One foo() { return this; } } class Three extends Two { // insert method here } Which methods, inserted individually, correctly complete the Three class?
a.public void foo() {}
b.public int foo() { return 3; }
c.public Two foo() { return this; }
d.public Object foo() { return this; }
7)Which statements is true?
a.A final method in class X can be abstract if and only if X is abstract.
b.A protected method in class X can be overridden by any subclass of X.
c.A private static method can be called only within other static methods in class X.
d.A non-static public final method in class X can be overridden in any subclass of X.
8)Given: public interface Status { /* insert code here */ int MY_VALUE = 10; } Which three are valid on line
9)A team of programmers is involved in reviewing a proposed design for a new utility class. After some discussion, they realize that the current design allows other classes to access methods in the utility class that should be accessible only to methods within the utility class itself. What design issue has the team discovered?
a.Weak encapsulation
b.Strong encapsulation
c.High cohesion
d.Tight coupling
10)Which of the following strings can be used as mode strings for creating a RandomAccessFile object? 
11)Given: public class TestOne { public static void main (String[] args) throws Exception { Thread.sleep(3000); System.out.println("sleep"); } } What is the result?
a.Compilation fails.
b.An exception is thrown at runtime.
c.The code executes normally and prints "sleep".
d.The code executes normally, but nothing is printed.
12)Given: class Mammal { } class Raccoon extends Mammal { Mammal m = new Mammal(); } class BabyRaccoon extends Mammal { } Which four statements are true?
a.Raccoon is-a Mammal.
b.BabyRaccoon has-a Mammal.
c.BabyRaccoon is-a Raccoon.
d.BabyRaccoon is-a BabyRaccoon.
13)Which of the following lines will not compile? byte b1=5, b2=3, b3; Short s=25; b2=s; b3=b1*b2;
a.Line 1only
b.Line 3 only
c.Line 4 only
d.Line 1 and 4 only
14)Given: class Nav{ public enum Direction { NORTH, SOUTH, EAST, WEST } } public class Sprite{ // insert code here } Which code,at "inserted code here", allows the Sprite class to compile?
a.Direction d = NORTH;
b.Nav.Direction d = NORTH;
c.Direction d = Direction.NORTH;
d.Nav.Direction d = Nav.Direction.NORTH;
15)Given: public static void main(String[] args) { Object obj = new int[] { 1, 2, 3 }; int[] someArray = (int[])obj; for (int i : someArray) System.out.print(i + " "); } What is the result?
a.1 2 3
b.Compilation fails because of an error
c.A ClassCastException is thrown at runtime.
16)Given: import java.util.*; public class SortOf { public static void main(String[] args) { public static void main(String[] args) { a.add(1); a.add(5); a.add(3); Collections.sort(a); a.add(2); Collections.reverse(a); System.out.println(a); } } What is the result?
a.[1, 2, 3, 5]
b.[2, 1, 3, 5]
c.[2, 5, 3, 1]
d.[5, 3, 2, 1]
17)Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object?
a.When using versions of Java technology earlier than 5.0.
b.When sharing a StringBuffer among multiple threads.
c.When using the class StringBufferInputStream.
d.When you plan to reuse the StringBuffer to build more than one string.
18)Which of the following statements are true?
a.Unicode characters are all 16 bits
b.UTF characters are all 24 bits
c.Reader class is byte stream class
19)Which statements are reserved words in Java?
20)DataInputStream is
a.An abstract class defined in
b.A class we can use to read primitive data type
c.An interface that defines methods to open files
d.An interface that defines methods to read primitive data types

For more such mcq please visit our partner

1 comment:

  1. If u can upload answer sheet at last, then it would certainly help to find mistakes.


Your comment may wait for moderation.... Protected by Copyscape Online Plagiarism Tool