Vidyalelo
Java Programming · all questions

Miscellaneous Java
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

121

Questions

5/7

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following Java program?
class string_class 
{
    public static void main(String args[])
    {
        String obj = "I LIKE JAVA";   
        System.out.println(obj.charAt(3));
    } 
}

Select an option to see the answer and solution.

Which annotation is used to represent command line input and assigned to correct data type?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class access
{
    public int x;
static int y;
    void cal(int a, int b)
    {
        x +=  a ;
        y +=  b;
    }        
}    
class static_specifier 
{
    public static void main(String args[])
    {
        access obj1 = new access();
        access obj2 = new access();   
        obj1.x = 0;
        obj1.y = 0;
        obj1.cal(1, 2);
        obj2.x = 0;
        obj2.cal(2, 3);
        System.out.println(obj1.x + " " + obj2.y);     
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java snippet, if compiled and executed with command line argument "java abc 1 2 3"?
public class abc
{
   static public void main(String [] xyz)
   {
       for(int n=1;n<xyz.length; n++)
       {
          System.out.println(xyz[n]+"");
       }
   }
}

Select an option to see the answer and solution.

Can command line arguments be converted into int automatically if required?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class string_class 
{
    public static void main(String args[])
    {
        String obj = "hello";
        String obj1 = "world";   
        String obj2 = obj;
        obj2 = " world";
        System.out.println(obj + " " + obj2);
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
class area 
{
    int width;
    int length;
    int height;
    area() 
    {
    width = 5;
    length = 6;
    height = 1;
    }
    void volume() 
    {
         volume = width * height * length;
    } 
}    
class cons_method 
{
    public static void main(String args[]) 
    {
        area obj = new area();
        obj.volume();
        System.out.println(obj.volume);
    } 
}

Select an option to see the answer and solution.

Arrays in Java are implemented as?

Select an option to see the answer and solution.

Which class allows parsing of command line arguments?

Select an option to see the answer and solution.

What will be the output of the following 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));
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program, Command line exceution is done as - "java Output This is a command Line"?
class Output 
{
    public static void main(String args[]) 
    {
        System.out.print(args[3]);
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java code snippet run as $ java Demo -length 512 -breadth 2 -h 3?
class Demo {
    @Parameter(names={"--length"})
    int length;
 
    @Parameter(names={"--breadth"})
    int breadth;
 
    @Parameter(names={"--height","-h"})
    int height;
 
    public static void main(String args[]) 
    {
        Demo demo = new Demo();
        new JCommander(demo, args);
        demo.run();
    }
 
    public void run() 
    {
        System.out.println(length+" "+ breadth+" "+height);
    }
}

Select an option to see the answer and solution.

Which of the following statements are incorrect?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class string_demo 
{
    public static void main(String args[])
    {
        String obj = "I" + "like" + "Java";   
        System.out.println(obj);     
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
class Output 
{
    static void main(String args[]) 
    {    
         int x , y = 1;
         x = 10;
         if(x != 10 && x / 0 == 0)
             System.out.println(y);
         else
             System.out.println(++y);
    } 
}

Select an option to see the answer and solution.

Which of these can be used to differentiate two or more methods having the same name?

Select an option to see the answer and solution.

Which of these is the method which is executed first before execution of any other thing takes place in a program?

Select an option to see the answer and solution.

Which one of the following is not an access modifier?

Select an option to see the answer and solution.

How many arguments can be passed to main()?

Select an option to see the answer and solution.

Which of these statement is incorrect?

Select an option to see the answer and solution.