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);

       }

}

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();

       }

}

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");

              }

       }

}

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");

              }

 

       }

}

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);

 

       }

}

 

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);

              }

       }

}

7. 
What will S2 contains after following lines of code?

String s1 = “One”;

String s2 = s1.concat(“Two”);

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());

       }

}

9. 
What is the output of this program?

Object[] names = new String[3];

names[0] = new Integer(0);

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);

}

}

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());

 

       }

}

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);

       }

}

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);

   }

}

14. 
What is the valid data types for variable “a” to print “Hello World”?

Switch(a)

{

System.out.println(“Hello World ”)

}

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);

       }

 

}

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;

       }

}

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);

       }

}


Leave a Reply

Your email address will not be published. Required fields are marked *