Explore topic-wise MCQs in Engineering.

This section includes 219 Mcqs, each offering curated multiple-choice questions to sharpen your Engineering knowledge and support exam preparation. Choose a topic below to get started.

201.

You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?

A. public
B. private
C. protected
D. default access
Answer» E.
202.

Which statement is true given the following?

Double d = Math.random();

A. 0.0 < d <= 1.0
B. 0.0 <= d < 1.0
C. Compilation fail
D. Cannot say.
Answer» C. Compilation fail
203.

Which two statements are true about wrapper or String classes?

  1. If x and y refer to instances of different wrapper classes, then the fragment x.equals(y) will cause a compiler failure.
  2. If x and y refer to instances of different wrapper classes, then x == y can sometimes be true.
  3. If x and y are String references and if x.equals(y) is true, then x == y is true.
  4. If x, y, and z refer to instances of wrapper classes and x.equals(y) is true, and y.equals(z) is true, then z.equals(x) will always be true.
  5. If x and y are String references and x == y is true, then y.equals(x) will be true.

A. 1 and 2
B. 2 and 3
C. 3 and 4
D. 4 and 5
Answer» E.
204.

Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?

A. (int)Math.min(d);
B. (int)Math.max(d);
C. (int)Math.abs(d);
D. (int)Math.floor(d);
Answer» E.
205.

What two statements are true about the result obtained from calling Math.random()?

  1. The result is less than 0.0.
  2. The result is greater than or equal to 0.0..
  3. The result is less than 1.0.
  4. The result is greater than 1.0.
  5. The result is greater than or equal to 1.0.

A. 1 and 2
B. 2 and 3
C. 3 and 4
D. 4 and 5
Answer» C. 3 and 4
206.

Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?

A. TreeMap
B. HashMap
C. LinkedHashMap
D. The answer depends on the implementation of the existing instance.
Answer» D. The answer depends on the implementation of the existing instance.
207.

Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?

A. java.lang.String
B. java.lang.Double
C. java.lang.StringBuffer
D. java.lang.Character
Answer» D. java.lang.Character
208.

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

A. java.util.HashSet
B. java.util.LinkedHashSet
C. java.util.List
D. java.util.ArrayList
Answer» E.
209.

Which interface does java.util.Hashtable implement?

A. Java.util.Map
B. Java.util.List
C. Java.util.HashTable
D. Java.util.Collection
Answer» B. Java.util.List
210.

You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?

A. java.util.Map
B. java.util.Set
C. java.util.List
D. java.util.Collection
Answer» C. java.util.List
211.

You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?

A. public
B. private
C. protected
D. transient
Answer» D. transient
212.

public class Outer { public void someOuterMethod() { //Line 5 } public class Inner { } public static void main(String[] argv) { Outer ot = new Outer(); //Line 10 } } 

Which of the following code fragments inserted, will allow to compile?

A. new Inner(); //At line 5
B. new Inner(); //At line 10
C. new ot.Inner(); //At line 10
D. new Outer.Inner(); //At line 10
Answer» B. new Inner(); //At line 10
213.

What is the value of "d" after this line of code has been executed?

double d = Math.round ( 2.5 + Math.random() );

A. 2
B. 3
C. 4
D. 2.5
Answer» C. 4
214.

interface Base { boolean m1 (); byte m2(short s);
}
which two code fragments will compile?
  1. interface Base2 implements Base {}
  2. abstract class Class2 extends Base
    { public boolean m1(){ return true; }}
  3. abstract class Class2 implements Base {}
  4. abstract class Class2 implements Base
    { public boolean m1(){ return (7 > 4); }}
  5. abstract class Class2 implements Base
    { protected boolean m1(){ return (5 > 7) }}

A. 1 and 2
B. 2 and 3
C. 3 and 4
D. 1 and 5
Answer» D. 1 and 5
215.

Which three form part of correct array declarations?

  1. public int a [ ]
  2. static int [ ] a
  3. public [ ] int a
  4. private int a [3]
  5. private int [3] a [ ]
  6. public final int [ ] a

A. 1, 3, 4
B. 2, 4, 5
C. 1, 2, 6
D. 2, 5, 6
Answer» D. 2, 5, 6
216.

public class Test { }
What is the prototype of the default constructor?

A. Test( )
B. Test(void)
C. public Test( )
D. public Test(void)
Answer» D. public Test(void)
217.

Which of the following would compile without error?

A. int a = Math.abs(-5);
B. int b = Math.abs(5.0);
C. int c = Math.abs(5.5F);
D. int d = Math.abs(5L);
Answer» B. int b = Math.abs(5.0);
218.

Which of the following are valid calls to Math.max?

  1. Math.max(1,4)
  2. Math.max(2.3, 5)
  3. Math.max(1, 3, 5, 7)
  4. Math.max(-1.5, -2.8f)

A. 1, 2 and 4
B. 2, 3 and 4
C. 1, 2 and 3
D. 3 and 4
Answer» B. 2, 3 and 4
219.

public class Myfile { public static void main (String[] args) { String biz = args[1]; String baz = args[2]; String rip = args[3]; System.out.println("Arg is " + rip); } }
Select how you would start the program to cause it to print: Arg is 2

A. java Myfile 222
B. java Myfile 1 2 2 3 4
C. java Myfile 1 3 2 2
D. java Myfile 0 1 2 3
Answer» D. java Myfile 0 1 2 3