

MCQOPTIONS
Saved Bookmarks
This section includes 46 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.
1. |
which two code fragments inserted at end of the program, will allow to compile? |
A. | 1 only |
B. | 2 only |
C. | 3 and 5 |
D. | 1 and 4 |
Answer» D. 1 and 4 | |
2. |
Which two statements are true for any concrete class implementing the java.lang.Runnable interface? |
A. | 1 and 3 |
B. | 2 and 4 |
C. | 1 and 5 |
D. | 2 and 6 |
Answer» E. | |
3. |
which two statements, added independently at beginning of the program, allow the code to compile? |
A. | 1 only |
B. | 2 and 5 |
C. | 3 and 4 |
D. | 3 and 5 |
Answer» C. 3 and 4 | |
4. |
Which three statements are true? |
A. | 1, 2 and 4 |
B. | 2, 3 and 5 |
C. | 3, 4 and 5 |
D. | 1, 2 and 3 |
Answer» C. 3, 4 and 5 | |
5. |
which statement is true? |
A. | The code compiles and runs, with output this 420 parent 420. |
B. | If line 18 is removed, the code will compile and run. |
C. | If line 20 is removed, the code will compile and run. |
D. | An exception is thrown at runtime. |
Answer» D. An exception is thrown at runtime. | |
6. |
Which is valid in a class that extends ? |
A. | public int method1(int a, int b) {return 0; } |
B. | private int method1(int a, int b) { return 0; } |
C. | public short method1(int a, int b) { return 0; } |
D. | static protected int method1(int a, int b) { return 0; } |
Answer» B. private int method1(int a, int b) { return 0; } | |
7. |
which two code fragments will compile? |
A. | 1 and 2 |
B. | 2 and 3 |
C. | 3 and 4 |
D. | 1 and 5 |
Answer» D. 1 and 5 | |
8. |
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 | |
9. |
The line that is not used to turn on the event scheduler is _________________ |
A. | event_scheduler = ON |
B. | eventscheduler = ON |
C. | event_scheduler_ON |
D. | events_scheduler_ON |
Answer» B. eventscheduler = ON | |
10. |
The statement that is used to check the status of the event scheduler at runtime is _____________ |
A. | SHOW STATUS OF ‘event_scheduler’ |
B. | SHOW VARIABLES OF ‘event_scheduler’ |
C. | SHOW STATUS LIKE ‘event_scheduler’ |
D. | SHOW VARIABLES LIKE ‘event_scheduler’ |
Answer» E. | |
11. |
Which table lists the accounts and the databases for which the privileges are provided? |
A. | user |
B. | db |
C. | tables_priv |
D. | procs_priv |
Answer» C. tables_priv | |
12. |
The security context when a user creates a stored program that accesses sensitive data but forgets that other people who can invoke the object have the same access is __________ |
A. | good |
B. | bad |
C. | illegal |
D. | fare |
Answer» C. illegal | |
13. |
The value of event_scheduler that enables checking status but not changing it at runtime is ______________ |
A. | ON |
B. | OFF |
C. | DISABLED |
D. | ENABLED |
Answer» D. ENABLED | |
14. |
Which variable checks for the availability of SSL support? |
A. | have_ssl |
B. | has_ssl |
C. | avail_ssl |
D. | ssl_avail |
Answer» B. has_ssl | |
15. |
What does ‘abc’ || ‘xyz’, when PIPES_AS_CONCAT is enabled, result in? |
A. | 0 |
B. | 1 |
C. | abcxyz |
D. | xyzabc |
Answer» D. xyzabc | |
16. |
What does the expression ‘2 BETWEEN 2 AND 5’ result in? |
A. | True |
B. | False |
C. | -1 |
D. | 2 |
Answer» B. False | |
17. |
Triggers are not supported for _____________ |
A. | delete |
B. | update |
C. | insert |
D. | views |
Answer» E. | |
18. |
How is a stored procedure invoked? |
A. | INVOKE |
B. | SEE |
C. | CALL |
D. | RETURN |
Answer» D. RETURN | |
19. |
Triggers and events are not invoked automatically by the server. |
A. | True |
B. | False |
C. | May be True or False |
D. | Can't say |
Answer» C. May be True or False | |
20. |
To check if the data directory contains insecure files or directories, the command executed is _____________ |
A. | ls -l |
B. | ls -a |
C. | ls -la |
D. | ls -lu |
Answer» D. ls -lu | |
21. |
What will be the output of the program? import java.util.*; public class NewTreeSet2 extends NewTreeSet { public static void main(String [] args) { NewTreeSet2 t = new NewTreeSet2(); t.count(); } } protected class NewTreeSet { void count() { for (int x = 0; x < 7; x++,x++ ) { System.out.print(" " + x); } } } |
A. | 0 2 4 |
B. | 0 2 4 6 |
C. | Compilation fails at line 2 |
D. | Compilation fails at line 10 |
Answer» E. | |
22. |
What will be the output of the program? class Base { Base() { System.out.print("Base"); } } public class Alpha extends Base { public static void main(String[] args) { new Alpha(); /* Line 12 */ new Base(); /* Line 13 */ } } |
A. | Base |
B. | BaseBase |
C. | Compilation fails |
D. | The code runs with no output |
Answer» C. Compilation fails | |
23. |
What will be the output of the program? class Super { public Integer getLength() { return new Integer(4); } } public class Sub extends Super { public Long getLength() { return new Long(5); } public static void main(String[] args) { Super sooper = new Super(); Sub sub = new Sub(); System.out.println( sooper.getLength().toString() + "," + sub.getLength().toString() ); } } |
A. | 4, 4 |
B. | 4, 5 |
C. | 5, 4 |
D. | Compilation fails. |
Answer» E. | |
24. |
What will be the output of the program? public class ArrayTest { public static void main(String[ ] args) { float f1[ ], f2[ ]; f1 = new float[10]; f2 = f1; System.out.println("f2[0] = " + f2[0]); } } |
A. | It prints f2[0] = 0.0 |
B. | It prints f2[0] = NaN |
C. | An error at f2 = f1; causes compile to fail. |
D. | It prints the garbage value. |
Answer» B. It prints f2[0] = NaN | |
25. |
What will be the output of the program? public class Test { public static void main(String args[]) { class Foo { public int i = 3; } Object o = (Object)new Foo(); Foo foo = (Foo)o; System.out.println("i = " + foo.i); } } |
A. | i = 3 |
B. | Compilation fails. |
C. | i = 5 |
D. | A ClassCastException will occur. |
Answer» B. Compilation fails. | |
26. |
Which cause a compiler error? |
A. | int[ ] scores = {3, 5, 7}; |
B. | int [ ][ ] scores = {2,7,6}, {9,3,45}; |
C. | String cats[ ] = {"Fluffy", "Spot", "Zeus"}; |
D. | boolean results[ ] = new boolean [] {true, false, true}; |
Answer» C. String cats[ ] = {"Fluffy", "Spot", "Zeus"}; | |
27. |
What will be the output of the program? public class A { void A() /* Line 3 */ { System.out.println("Class A"); } public static void main(String[] args) { new A(); } } |
A. | Class A |
B. | Compilation fails. |
C. | An exception is thrown at line 3. |
D. | The code executes with no output. |
Answer» E. | |
28. |
Which two of the following are legal declarations for nonnested classes and interfaces? final abstract class Test {} public static interface Test {} final public class Test {} protected abstract class Test {} protected interface Test {} abstract public class Test {} |
A. | 1 and 4 |
B. | 2 and 5 |
C. | 3 and 6 |
D. | 4 and 6 |
Answer» D. 4 and 6 | |
29. |
Which three statements are true? The default constructor initialises method variables. The default constructor has the same access as its class. The default constructor invokes the no-arg constructor of the superclass. If a class lacks a no-arg constructor, the compiler always creates a default constructor. The compiler creates a default constructor only when there are no other constructors for the class. |
A. | 1, 2 and 4 |
B. | 2, 3 and 5 |
C. | 3, 4 and 5 |
D. | 1, 2 and 3 |
Answer» C. 3, 4 and 5 | |
30. |
What will be the output of the program? interface Count { short counter = 0; void countUp(); } public class TestCount implements Count { public static void main(String [] args) { TestCount t = new TestCount(); t.countUp(); } public void countUp() { for (int x = 6; x>counter; x--, ++counter) /* Line 14 */ { System.out.print(" " + counter); } } } |
A. | 0 1 2 |
B. | 1 2 3 |
C. | 0 1 2 3 |
D. | 1 2 3 4 |
Answer» E. | |
31. |
package testpkg.p1; public class ParentUtil { public int x = 420; protected int doStuff() { return x; } } package testpkg.p2; import testpkg.p1.ParentUtil; public class ChildUtil extends ParentUtil { public static void main(String [] args) { new ChildUtil().callStuff(); } void callStuff() { System.out.print("this " + this.doStuff() ); /* Line 18 */ ParentUtil p = new ParentUtil(); System.out.print(" parent " + p.doStuff() ); /* Line 20 */ } } which statement is true? |
A. | The code compiles and runs, with output this 420 parent 420. |
B. | If line 18 is removed, the code will compile and run. |
C. | If line 20 is removed, the code will compile and run. |
D. | An exception is thrown at runtime. |
Answer» D. An exception is thrown at runtime. | |
32. |
What will be the output of the program? class Super { public int i = 0; public Super(String text) /* Line 4 */ { i = 1; } } class Sub extends Super { public Sub(String text) { i = 2; } public static void main(String args[]) { Sub sub = new Sub("Hello"); System.out.println(sub.i); } } |
A. | 0 |
B. | 1 |
C. | 2 |
D. | Compilation fails. |
Answer» E. | |
33. |
Which two statements are true for any concrete class implementing the java.lang.Runnable interface? You can extend the Runnable interface as long as you override the public run() method. The class must contain a method called run() from which all code for that thread will be initiated. The class must contain an empty public void method named run(). The class must contain a public void method named runnable(). The class definition must include the words implements Threads and contain a method called run(). The mandatory method must be public, with a return type of void, must be called run(), and cannot take any arguments. |
A. | 1 and 3 |
B. | 2 and 4 |
C. | 1 and 5 |
D. | 2 and 6 |
Answer» E. | |
34. |
class A { protected int method1(int a, int b) { return 0; } } Which is valid in a class that extends class A? |
A. | public int method1(int a, int b) {return 0; } |
B. | private int method1(int a, int b) { return 0; } |
C. | public short method1(int a, int b) { return 0; } |
D. | static protected int method1(int a, int b) { return 0; } |
Answer» B. private int method1(int a, int b) { return 0; } | |
35. |
Which three are valid method signatures in an interface? private int getArea(); public float getVol(float x); public void main(String [] args); public static void main(String [] args); boolean setFlag(Boolean [] test); |
A. | 1 and 2 |
B. | 2, 3 and 5 |
C. | 3, 4, and 5 |
D. | 2 and 4 |
Answer» C. 3, 4, and 5 | |
36. |
What will be the output of the program? public class Test { public int aMethod() { static int i = 0; i++; return i; } public static void main(String args[]) { Test test = new Test(); test.aMethod(); int j = test.aMethod(); System.out.println(j); } } |
A. | 0 |
B. | 1 |
C. | 2 |
D. | Compilation fails. |
Answer» E. | |
37. |
Which of the following is/are legal method declarations? protected abstract void m1(); static final void m1(){} synchronized public final void m1() {} private native void m1(); |
A. | 1 and 3 |
B. | 2 and 4 |
C. | 1 only |
D. | All of them are legal declarations. |
Answer» E. | |
38. |
/* Missing statements ? */ public class NewTreeSet extends java.util.TreeSet { public static void main(String [] args) { java.util.TreeSet t = new java.util.TreeSet(); t.clear(); } public void clear() { TreeMap m = new TreeMap(); m.clear(); } } which two statements, added independently at beginning of the program, allow the code to compile? No statement is required import java.util.*; import.java.util.Tree*; import java.util.TreeSet; import java.util.TreeMap; |
A. | 1 only |
B. | 2 and 5 |
C. | 3 and 4 |
D. | 3 and 5 |
Answer» C. 3 and 4 | |
39. |
interface DoMath { double getArea(int rad); } interface MathPlus { double getVol(int b, int h); } /* Missing Statements ? */ which two code fragments inserted at end of the program, will allow to compile? class AllMath extends DoMath { double getArea(int r); } interface AllMath implements MathPlus { double getVol(int x, int y); } interface AllMath extends DoMath { float getAvg(int h, int l); } class AllMath implements MathPlus { double getArea(int rad); } abstract class AllMath implements DoMath, MathPlus { public double getArea(int rad) { return rad * rad * 3.14; } } |
A. | 1 only |
B. | 2 only |
C. | 3 and 5 |
D. | 1 and 4 |
Answer» D. 1 and 4 | |
40. |
Which two cause a compiler error? float[ ] f = new float(3); float f2[ ] = new float[ ]; float[ ]f1 = new float[3]; float f3[ ] = new float[3]; float f5[ ] = {1.0f, 2.0f, 2.0f}; |
A. | 2, 4 |
B. | 3, 5 |
C. | 4, 5 |
D. | 1, 2 |
Answer» E. | |
41. |
interface Base { boolean m1 (); byte m2(short s); } which two code fragments will compile? interface Base2 implements Base {} abstract class Class2 extends Base { public boolean m1(){ return true; }} abstract class Class2 implements Base {} abstract class Class2 implements Base { public boolean m1(){ return (7 > 4); }} 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 | |
42. |
What is the widest valid returnType for methodA in line 3? public class ReturnIt { returnType methodA(byte x, double y) /* Line 3 */ { return (long)x / y * 2; } } |
A. | int |
B. | byte |
C. | long |
D. | double |
Answer» E. | |
43. |
What will be the output of the program? class A { final public int GetResult(int a, int b) { return 0; } } class B extends A { public int GetResult(int a, int b) {return 1; } } public class Test { public static void main(String args[]) { B b = new B(); System.out.println("x = " + b.GetResult(0, 1)); } } |
A. | x = 0 |
B. | x = 1 |
C. | Compilation fails. |
D. | An exception is thrown at runtime. |
Answer» D. An exception is thrown at runtime. | |
44. |
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) | |
45. |
Which three form part of correct array declarations? public int a [ ] static int [ ] a public [ ] int a private int a [3] private int [3] a [ ] 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 | |
46. |
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 | |