

MCQOPTIONS
Saved Bookmarks
This section includes 1698 Mcqs, each offering curated multiple-choice questions to sharpen your General Awareness knowledge and support exam preparation. Choose a topic below to get started.
651. |
What is the output of this program? import java.io.*; public class filesinputoutput { public static void main(String[] args) { String obj = "abc"; byte b[] = obj.getBytes(); ByteArrayInputStream obj1 = new ByteArrayInputStream(b); for (int i = 0; i < 2; ++ i) { int c; while ((c = obj1.read()) != -1) { if (i == 0) { System.out.print(Character.toUpperCase((char)c)); } } } } } |
A. | Abc |
B. | ABC |
C. | Ab |
D. | AB |
Answer» C. Ab | |
652. |
What value will this program return to Java run-time system? import java.lang.System; class Output { public static void main(String args[]) { System.exit(5); } } |
A. | 0 |
B. | 1 |
C. | 4 |
D. | 5 |
Answer» E. | |
653. |
What is the output of this program? import java.io.*; public class filesinputoutput { public static void main(String[] args) { String obj = "abc"; byte b[] = obj.getBytes(); ByteArrayInputStream obj1 = new ByteArrayInputStream(b); for (int i = 0; i < 2; ++ i) { int c; while ((c = obj1.read()) != -1) { if (i == 0) { System.out.print(Character.toUpperCase((char)c)); obj2.write(1); } } System.out.print(obj2); } } } |
A. | AaBaCa |
B. | ABCaaa |
C. | AaaBaaCaa |
D. | AaBaaCaaa |
Answer» E. | |
654. |
What is the output of this program? class exception_handling { static void throwexception() throws ArithmeticException { System.out.print("0"); throw new ArithmeticException ("Exception"); } public static void main(String args[]) { try { throwexception(); } catch (ArithmeticException e) { System.out.println("A"); } } } |
A. | A |
B. | 0 |
C. | 0A |
D. | Exception |
Answer» D. Exception | |
655. |
What is the output of this program? class exception_handling { public static void main(String args[]) { try { int a = 1; int b = 10 / a; try { if (a == 1) a = a / a - a; if (a == 2) { int c[] = {1}; c[8] = 9; } finally { System.out.print("A"); } } catch (NullPointerException e) { System.out.println("B"); } } } |
A. | A |
B. | B |
C. | AB |
D. | BA |
Answer» B. B | |
656. |
What is the output of this program? class dynamic_initialization { public static void main(String args[]) { double a, b; a = 3.0; b = 4.0; double c = Math.sqrt(a * a + b * b); System.out.println(c); } } |
A. | 5.0 |
B. | 25.0 |
C. | 7.0 |
D. | Compilation Error |
Answer» B. 25.0 | |
657. |
What is the output of this program? class variable_scope { public static void main(String args[]) { int x; x = 5; { int y = 6; System.out.print(x + " " + y); } System.out.println(x + " " + y); } } |
A. | 5 6 5 6 |
B. | 5 6 5 |
C. | Runtime error |
D. | Compilation error |
Answer» E. | |
658. |
Which of these is an incorrect string literal? |
A. | Hello World |
B. | Hello nWorld |
C. | Hello World |
D. | "Hello world" |
Answer» E. | |
659. |
What is the output of this program? class A { final public int calculate(int a, int b) { return 1; } } class B extends A { public int calculate(int a, int b) { return 2; } } public class output { public static void main(String args[]) { B object = new B(); System.out.print("b is " + b.calculate(0, 1)); } } |
A. | B is : 2 |
B. | B is : 1 |
C. | Compilation Error |
D. | An exception is thrown at runtime |
Answer» D. An exception is thrown at runtime | |
660. |
What is the output of this program? class c { public void main( String[] args ) { System.out.println( "Hello" + args[0] ); } } |
A. | Hello c |
B. | Hello |
C. | Hello world |
D. | Runtime Error |
Answer» E. | |
661. |
What is the output of this program? class evaluate { public static void main(String args[]) { int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 6; n = arr[arr[n] / 2]; System.out.println(arr[n] / 2); } } |
A. | 3 |
B. | 0 |
C. | 6 |
D. | 1 |
Answer» E. | |
662. |
What is the output of this program? class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = 'i'; System.out.print(array_variable[i] + ""); } } } |
A. | 1 2 3 4 5 6 7 8 9 10 |
B. | 0 1 2 3 4 5 6 7 8 9 10 |
C. | I j k l m n o p q r |
D. | I i i i i i i i i i |
Answer» E. | |
663. |
What is the output of this program? class array_output { public static void main(String args[]) { int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}}; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3 ; ++j) sum = sum + array_variable[i][j]; System.out.print(sum / 5); } } |
A. | 8 |
B. | 9 |
C. | 10 |
D. | 11 |
Answer» C. 10 | |
664. |
Which two cause a compiler error? 1. float[ ] f = new float(3); 2. float f2[ ] = new float[ ]; 3. float[ ]f1 = new float[3]; 4. float f3[ ] = new float[3]; 5. float f5[ ] = {1.0f, 2.0f, 2.0f}; |
A. | 2, 4 |
B. | 3, 5 |
C. | 4, 5 |
D. | 1, 2 |
Answer» E. | |
665. |
Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class? |
A. | Final |
B. | Static |
C. | Private |
D. | Protected |
Answer» D. Protected | |
666. |
Which of the following are legal lines of Java code? 1. int w = (int)888.8; 2. byte x = (byte)100L; 3. long y = (byte)100; 4. byte z = (byte)100L; |
A. | 1 and 2 |
B. | 2 and 3 |
C. | 3 and 4 |
D. | All statements are correct |
Answer» E. | |
667. |
What will be the output of these statement? class output { public static void main(String args[]) { double a, b,c; a = 3.0/0; b = 0/4.0; c=0/0.0; System.out.println(a); System.out.println(b); System.out.println(c); } } |
A. | Infinity |
B. | 0.0 |
C. | NaN |
D. | All of the mentioned |
Answer» E. | |
668. |
What is the output of this program? class average { public static void main(String args[]) { double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5}; double result; result = 0; for (int i = 0; i < 6; ++i) result = result + num[i]; System.out.print(result/6); } } |
A. | 16.34 |
B. | 16.566666644 |
C. | 16.46666666666667 |
D. | 16.46666666666666 |
Answer» D. 16.46666666666666 | |
669. |
What is the output of this program? class increment { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } } |
A. | 25 |
B. | 24 |
C. | 32 |
D. | 33 |
Answer» D. 33 | |
670. |
What is the output of this program? class area { public static void main(String args[]) { double r, pi, a; r = 9.8; pi = 3.14; a = pi * r * r; System.out.println(a); } } |
A. | 301.5656 |
B. | 301 |
C. | 301.56 |
D. | 301.56560000 |
Answer» B. 301 | |
671. |
What is the output of this program? class mainclass { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; if (var1) System.out.println(var1); else System.out.println(var2); } } |
A. | 0 |
B. | 1 |
C. | True |
D. | False |
Answer» D. False | |
672. |
What is the output of this program? class booloperators { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; System.out.println((var1 & var2)); } } |
A. | 0 |
B. | 1 |
C. | True |
D. | False |
Answer» E. | |
673. |
What is the output of this program? class asciicodes { public static void main(String args[]) { char var1 = 'A'; char var2 = 'a'; System.out.println((int)var1 + " " + (int)var2); } } |
A. | 162 |
B. | 65 97 |
C. | 67 95 |
D. | 66 98 |
Answer» C. 67 95 | |
674. |
How to convert a String to a Date object? |
A. | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.parse(new Date()); |
B. | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date()); |
C. | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().parse(); |
D. | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().format(); |
Answer» B. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date()); | |
675. |
What is the output of this program? import java.io.*; class streams { public static void main(String[] args) { try { FileOutputStream fos = new FileOutputStream("serial"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeFloat(3.5); oos.flush(); oos.close(); } catch(Exception e) { System.out.println("Serialization" + e); System.exit(0); } try { float x; FileInputStream fis = new FileInputStream("serial"); ObjectInputStream ois = new ObjectInputStream(fis); x = ois.readInt(); ois.close(); System.out.println(x); } catch (Exception e) { System.out.print("deserialization"); System.exit(0); } } } |
A. | 3 |
B. | 3.5 |
C. | Serialization |
D. | Serialization |
Answer» C. Serialization | |
676. |
What is the output of this program? import java.io.*; class streams { public static void main(String[] args) { try { FileOutputStream fos = new FileOutputStream("serial"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeFloat(3.5); oos.flush(); oos.close(); } catch(Exception e) { System.out.println("Serialization" + e); System.exit(0); } try { FileInputStream fis = new FileInputStream("serial"); ObjectInputStream ois = new ObjectInputStream(fis); ois.close(); System.out.println(ois.available()); } catch (Exception e) { System.out.print("deserialization"); System.exit(0); } } } |
A. | 1 |
B. | 2 |
C. | 3 |
D. | 0 |
Answer» E. | |
677. |
What is the output of this program? import java.io.*; class streams { public static void main(String[] args) { try { FileOutputStream fos = new FileOutputStream("serial"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeFloat(3.5); oos.flush(); oos.close(); } catch(Exception e) { System.out.println("Serialization" + e); System.exit(0); } try { FileInputStream fis = new FileInputStream("serial"); ObjectInputStream ois = new ObjectInputStream(fis); System.out.println(ois.available()); } catch (Exception e) { System.out.print("deserialization"); System.exit(0); } } } |
A. | 1 |
B. | 2 |
C. | 3 |
D. | 4 |
Answer» E. | |
678. |
What will be printed to the output and written to the file, in the below program? import java.io.FileOutputStream; public class FileOutputStreamExample { public static void main(String args[]) { try { FileOutputStream fout=new FileOutputStream("D: mcqsmentor.txt"); String s="Welcome to Compscibits"; byte b[]=s.getBytes();//converting string into byte array fout.write(b); fout.close(); System.out.println("Success"); } catch(Exception e){System.out.println(e);} } } |
A. | Success to the output and Welcome to Compscibits to the file |
B. | only Welcome to Compscibits to the file |
C. | Compile time error |
D. | No Output |
Answer» B. only Welcome to Compscibits to the file | |
679. |
What is the output of this program? import java.io.*; import java.net.*; public class URLDemo { public static void main(String[] args) { try { URL url=new URL("https://www.mcqsmentor.com/Java-Programming"); System.out.println("Protocol: "+url.getProtocol()); System.out.println("Host Name: "+url.getHost()); System.out.println("Port Number: "+url.getPort()); } catch(Exception e){System.out.println(e);} } } |
A. | Protocol: http |
B. | Host Name: www.mcqsmentor.com |
C. | Port Number: -1 |
D. | All of the mentioned |
Answer» E. | |
680. |
What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws UnknownHostException { InetAddress obj1 = InetAddress.getByName("cisco.com"); System.out.print(obj1.getHostName()); } } |
A. | Cisco |
B. | Cisco.com |
C. | Www.cisco.com |
D. | None of the mentioned |
Answer» C. Www.cisco.com | |
681. |
What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws MalformedURLException { URL obj = new URL("https://www.mcqsmentor.com/mcq-questions/Java-Programming"); System.out.print(obj.toExternalForm()); } } |
A. | mcqsmentor |
B. | mcqsmentor.com |
C. | Www.mcqsmentor.com |
D. | Https://www.mcqsmentor.com/mcq-questions/Java-Programming |
Answer» D. Https://www.mcqsmentor.com/mcq-questions/Java-Programming | |
682. |
What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws MalformedURLException { URL obj = new URL("https://www.compscibits.com/mcq-questions/Java-Programming"); System.out.print(obj.getHost()); } } |
A. | mcqsmentor |
B. | mcqsmentor.com |
C. | Www.mcqsmentor.com |
D. | Https://www.mcqsmentor.com/mcq-questions/Java-Programming |
Answer» E. | |
683. |
What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws MalformedURLException { URL obj = new URL("https://www.mcqsmentor.com/"); System.out.print(obj.getProtocol()); } } |
A. | Http |
B. | Https |
C. | Www |
D. | Com |
Answer» B. Https | |
684. |
What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws MalformedURLException { URL obj = new URL("https://www.mcqsmentor.com/j"); System.out.print(obj.getPort()); } } |
A. | 1 |
B. | 0 |
C. | -1 |
D. | Garbage value |
Answer» D. Garbage value | |
685. |
What is the output of this program? class X { int a; double b; } class Y extends X { int c; } class Output { public static void main(String args[]) { X a = new X(); Y b = new Y(); Class obj; obj = a.getClass(); System.out.print(obj.getName()); } } |
A. | X |
B. | Y |
C. | A |
D. | B |
Answer» B. Y | |
686. |
What is the output of this program? class X { int a; double b; } class Y extends X { int c; } class Output { public static void main(String args[]) { X a = new X(); Y b = new Y(); Class obj; obj = b.getClass(); System.out.print(obj.isLocalClass()); } } |
A. | 0 |
B. | 1 |
C. | True |
D. | False |
Answer» E. | |
687. |
What is the output of this program? class newthread implements Runnable { Thread t1,t2; newthread() { t1 = new Thread(this,"Thread_1"); t2 = new Thread(this,"Thread_2"); t1.start(); t2.start(); } public void run() { t2.setPriority(Thread.MAX_PRIORITY); System.out.print(t1.equals(t2)); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } |
A. | True |
B. | False |
C. | Truetrue |
D. | Falsefalse |
Answer» E. | |
688. |
What is the output of this program? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"New Thread"); t.start(); } public void run() { t.setPriority(Thread.MAX_PRIORITY); System.out.println(t); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } |
A. | Thread[New Thread,0,main]. |
B. | Thread[New Thread,1,main]. |
C. | Thread[New Thread,5,main]. |
D. | Thread[New Thread,10,main]. |
Answer» E. | |
689. |
What is the output of this program? class Output { public static void main(String args[]) { double x = 3.14; int y = (int) Math.toRadians(x); System.out.print(y); } } |
A. | 0 |
B. | 3 |
C. | 3.0 |
D. | 3.1 |
Answer» B. 3 | |
690. |
What is the output of this program? class Output { public static void main(String args[]) { double x = 3.14; int y = (int) Math.toDegrees(x); System.out.print(y); } } |
A. | 0 |
B. | 179 |
C. | 180 |
D. | 360 |
Answer» C. 180 | |
691. |
What is the output of this program? class X { int a; double b; } class Y extends X { int c; } class Output { public static void main(String args[]) { X a = new X(); Y b = new Y(); Class obj; obj = b.getClass(); System.out.print(obj.getSuperclass()); } } |
A. | X |
B. | Y |
C. | Class X |
D. | Class Y |
Answer» D. Class Y | |
692. |
What is the output of this program? class X { int a; double b; } class Y extends X { int c; } class Output { public static void main(String args[]) { X a = new X(); Y b = new Y(); Class obj; obj = b.getClass(); System.out.print(b.equals(a)); } } |
A. | 0 |
B. | 1 |
C. | True |
D. | False |
Answer» E. | |
693. |
What is the output of this program? class X { int a; double b; } class Y extends X { int c; } class Output { public static void main(String args[]) { X a = new X(); Y b = new Y(); Class obj; obj = b.getClass(); System.out.print(obj.isInstance(a)); } } |
A. | 0 |
B. | 1 |
C. | True |
D. | False |
Answer» E. | |
694. |
Which of the following code fragments inserted, will allow to compile? public class Outer { public void someOuterMethod() { //Line 5 } public class Inner { } public static void main(String[] argv) { Outer ot = new Outer(); //Line 10 } } |
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 | |
695. |
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) }} interface Base { boolean m1 (); byte m2(short s); } |
A. | 1 and 2 |
B. | 2 and 3 |
C. | 3 and 4 |
D. | 1 and 5 |
Answer» D. 1 and 5 | |
696. |
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 | |
697. |
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) | |
698. |
Which of the following is/are legal method declarations? 1. protected abstract void m1(); 2. static final void m1(){} 3. synchronized public final void m1() {} 4. private native void m1(); |
A. | 1 and 3 |
B. | 2 and 4 |
C. | 1 only |
D. | All of them are legal declarations. |
Answer» E. | |
699. |
Which three are valid method signatures in an interface? 1. private int getArea(); 2. public float getVol(float x); 3. public void main(String [] args); 4. public static void main(String [] args); 5. 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 | |
700. |
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. | |