Java Program Quiz May 20, 2021 Leave a Comment on Java Program Quiz Welcome to your Java Program Quiz For your information, please note that this Java Program quiz basic level has only single choice questions. Read each and every questions carefully before you start answering.You will have 10 min to complete the quiz. Press the Start quiz button to initiate the quiz. Once complete you press Finish button to complete the test. After completion of test you can see your quiz result with sharing option, You can share your quiz result to social media like Facebook, Instagram etc. Note: You can view all the answers at the end of this quiz. Best of luck for Java Program Quiz 1. What will be output of the below program? class MainClass{ public static void main(String args[]) { double var1 = 1+5; double var2 = var1/4; int var3 = 1+5; int var4 = var3/4; System.out.println(var2 + " " + var4); } } 1.5 1.0 0 1 1.5 1 1 1 2. What is the output of this program? class newthread extends Thread { Thread t; newthread() { t = new Thread(this, "My Thread"); t.start(); } public void run() { try{ t.join(); System.out.println(t.getName()); } catch(Exception e) { System.out.println("Exception"); } } } class multithreading{ public static void main(String args[]) { new newthread(); } } Runtime Error Exception Thread[My Thread, 5, main] My Thread 3. What is the output of this program? class exception{ public static void main(String args[]) { try{ int i,sum; sum =10; for(i =-1; i<3; ++i){ sum = (sum/i); System.out.println(i); } } catch(ArithmeticException e) { System.out.println("0"); } } } -101 -10 -1 0 4. What is the output of this program? class execption_handling{ public static void main(String args[]) { try{ int a,b; b = 0; a = 5/b; System.out.println("A"); } catch(ArithmeticException e){ System.out.println("B"); } finally{ System.out.println("C"); } } } A AC BC B 5. Which of the output of this program? class String_demo{ public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); String s1 = "abcd"; int len1 = s1.length(); int len2 = s.length(); System.out.println(len1 + " " + len2); } } 3 0 0 3 4 3 3 4 6. What will be the output of this program? class comma{ public static void main(String args[]) { int sum = 0; for (int i = 0, j = 0; i<5& j<5; ++i, j=i+1) { sum+=i; System.out.println(sum); } } } 5 14 6 d. Compilation Error 7. What will S2 contains after following lines of code? String s1 = “One”; String s2 = s1.concat(“Two”); TwoOne One Two OneTwo 8. What is the output if this program? class A { int i; int j; A(){ i = 1; j = 2; } } class Output{ public static void main(String args[]){ A obj1 = new A(); System.out.println(obj1.toString()); } } String associated with obj1 False Compilation Error True 9. What is the output of this program? Object[] names = new String[3]; names[0] = new Integer(0); ArrayIndexOutOfBoundsException Compilation Error Codes run Successfully ArrayStoreException 10. What is the output if this program? class String_demo { Public static void main(String args[]) { Int ascii[] = {65, 66, 67,68}; String s = new String(ascii, 1,3); System.out.println(s); } } CDA ABC BCD ABCD 11. what will be the output of this program? import java.util.*; class Output{ public static void main(String args[]) { ArrayList obj = new ArrayList(); obj.add("A"); obj.ensureCapacity(3); System.out.println(obj.size()); } } 1 2 4 3 12. What is the output of this program? class box{ int width; int height; int length; int volume; void volume(int height,int length, int width) { volume = width* height * length; } } class Parameterized{ public static void main (String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width =5; obj.volume(3,2,1); System.out.println(obj.volume); } } 25 6 1 0 13. What is the output of this program? class Outout{ public static void main(String args[] ) { int a = 1; int b = 2; int c = 3; a |= 4; b>>=1; c<<=1; a^=c; System.out.println(a +"" + b + "" + c); } } 3 1 6 3 3 6 2 2 3 2 3 4 14. What is the valid data types for variable “a” to print “Hello World”? Switch(a) { System.out.println(“Hello World ”) } int and float byte and short byte and char char and long 15. What is the output of the below program? class ternary_operator{ public static void main(String args[]) { int x=3; int y =~x; int z; z = x > y ? x:y; System.out.println(z); } } 3 1 2 4 16. What is the Output of he below code snippet? enum Enums { A,B,C; private Enums() { System.out.println(10); } } public class MainClass{ public static void main(String args[]) { Enum en = Enums B; } } 1010 101010 Compilation Error Runtime Exception 17. What will be the Output of this program? class test{ int a; int b; void method(int i, int j) { i*=2; j*=2; } } class Output{ public static void main(String args[]) { test obj =new test(); int a=10; int b= 20; obj.method(a, b); System.out.println(a+" " + b); } } 20 40 20 10 40 20 10 20 Please fill in the comment box below.