github

Made bySaurav Hathi

MCQ Test Java: Input and Output

Q1:

What will be the output of this java code?

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

 }

 }

Tags:
Section:
Core Programming
Options:
Q2:

What is the output of this java program?

 class increment

{

 public static void main(String args[])

 {       

 int g = 3;

 System.out.print(++g * 8);

 }

 }

Tags:
Section:
Core Programming
Options:
Q3:

What is the output of this java program?

class operators

{

public static void main(String args[])

{

int var1 = 5;

int var2 = 6;

int var3;

var3 = ++ var2 * var1 / var2 + var2;

System.out.print(var3);

}

}

Tags:
Section:
Core Programming
Options:
Q4:

What is the valid data type for variable “a” to print “Hello World” in java?

switch(a)

{

System.out.println("Hello World");

}

Tags:
Section:
Core Programming
Options:
Q5:

What is the output of this java program?

class string_class

{

public static void main(String args[ ])

{

String obj = "hello";

String obj1 = "world";

String obj2 = "hello";

System.out.println(obj.equals(obj1) + " " + obj.equals(obj2));

}

}

Tags:
Section:
Core Programming
Options:
Q6:

What is the output of this java program?

class Abc

{

    public static void main(String[]args)

    {

        String[] elements = { "for", "tea", "too" };

        String first = (elements.length > 0) ? elements[0]: null;

    }

}

Tags:
Section:
Core Programming
Options:
Q7:

What is the output of this java 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);

    }

}

Tags:
Section:
Core Programming
Options:
Q8:

What is the output of this java 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.print(obj1.toString());

     }

}

Tags:
Section:
Core Programming
Options:
Q9:

What is the output of this java program?

class output

{

    public static void main(String args[])

    {

       String c= "Hello i love java";

       int start = 2;

       int end = 9;

       char s[]=new char[end-start];

       c.getChars(start,end,s,0);

       System.out.println(s);

    }

}

Tags:
Section:
Core Programming
Options:
Q10:

What is the output of this java program?

class bitwise_operator

{

public static void main(String args[])

{

int var1 = 42;

int var2 = ~var1;

System.out.print(var1 + " " + var2);        

}

}

Tags:
Section:
Core Programming
Options:
Q11:

Which of these functions is called to display the output of an applet ?

Tags:
Section:
Core Programming
Options:
Q12:

Which of these methods can be used to output a string in an applet?

Tags:
Section:
Core Programming
Options:
Q13:

What is the Message displayed in the applet made by this program?

import java.awt.*;

import java.applet.*;

public class myapplet extends Applet

{

     public void paint(Graphics g)

     {

         g.drawString("A Simple Applet", 20, 20);   

     }

}

Tags:
Section:
Core Programming
Options:
Q14:

What is the length of the application box made by this program?

import java.awt.*;

import java.applet.*;

public class myapplet extends Applet

{

     public void paint(Graphics g)

     {

         g.drawString("A Simple Applet", 20, 20);

     }

}

Tags:
Section:
Core Programming
Options:
Q15:

What is the output of this java program?

import java.io.*;

class Chararrayinput

{

     public static void main(String[] args)

     {

         String obj  = "abcdefgh";

         int length = obj.length();

         char c[] = new char[length];

         obj.getChars(0, length, c, 0);

         CharArrayReader input1 = new CharArrayReader(c);

         CharArrayReader input2 = new CharArrayReader(c, 1, 4);

         int i;

         int j;

         try

         {

             while((i = input1.read()) == (j = input2.read()))

             {

                 System.out.print((char)i);

             }

         }   

         catch (IOException e)

         {

             e.printStackTrace();

          }

     }

}

Tags:
Section:
Core Programming
Options:
Q16:

What is the output of this java program?

class output

{

    public static void main(String args[])

    {

        char c[]={'a', '1', 'b' ,' ' ,'A' , '0'};

        for (int i = 0; i < 5; ++i)

        {

               if(Character.isDigit(c[i]))

                   System.out.println(c[i]+" is a digit");

               if(Character.isWhitespace(c[i]))

                   System.out.println(c[i]+" is a Whitespace character");

               if(Character.isUpperCase(c[i]))

                   System.out.println(c[i]+" is an Upper case Letter");

               if(Character.isLowerCase(c[i]))

                   System.out.println(c[i]+" is a lower case Letter");

               i=i+3;

        }

    }

}

Tags:
Section:
Core Programming
Options:
Q17:

What is the output of this java program?

class output

{

    public static void main(String args[])

    {

       String c = "Hello i love java";

       boolean var;

       var = c.startsWith("hello");

       System.out.println(var);

    }

}

Tags:
Section:
Core Programming
Options:
Q18:

What is the output of this java program?

class output

{

    public static void main(String args[])

    {

         String chars[] = {"a", "b", "c", "a", "c"};

         for (int i = 0; i < chars.length; ++i)

             for (int j = i + 1; j < chars.length; ++j)

                 if(chars[i].compareTo(chars[j]) == 0)

                     System.out.print(chars[j]);

    }

}

Tags:
Section:
Core Programming
Options:
Q19:

What is the output of this java program?

class output

{

    public static void main(String args[])

    {

       String c = "  Hello World  ";

       String s = c.trim();

       System.out.println("\""+s+"\"");

    }

}

Tags:
Section:
Core Programming
Options:
Q20:

What is the output of this java program?

class output

{

    public static void main(String args[])

    {

          String s = "Hello World";

          int i = s.indexOf('o');

          int j = s.lastIndexOf('l');

          System.out.print(i + " " + j);

    }

}

Tags:
Section:
Core Programming
Options: