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

6/7

Page

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

Which of these keywords is used to refer to member of base class from a subclass?

Select an option to see the answer and solution.

All the variables of class should be ideally declared as?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of these data type can be used for a method having a return statement in it?

Select an option to see the answer and solution.

What will be the output of the following Java snippet, if attempted to compile and execute?
class abc
{
    public static void main(String args[])
    {
        if(args.length>0)
        System.out.println(args.length);
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is the use of @syntax?

Select an option to see the answer and solution.

Which of these data types is used to store command line arguments?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class access
{
   static int x;
   void increment()
   {
       x++;
   }   
 }   
class static_use 
{
    public static void main(String args[])
    {
        access obj1 = new access();
        access obj2 = new access();
        obj1.x = 0;   
        obj1.increment();
        obj2.increment();
        System.out.println(obj1.x + " " + obj2.x);
     }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Java program?
class Output 
{
    public static void main(String args[])
    {
        int a1[] = new int[10];
        int a2[] = {1, 2, 3, 4, 5};
        System.out.println(a1.length + " " + a2.length);
    } 
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
class box 
{
    int width;
    int height;
    int length;
    int volume;
    void volume(int height, int length, int width) 
    {
         volume = width * height * length;
    } 
}    
class Prameterized_method{
    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);        
    } 
}

Select an option to see the answer and solution.

String in Java is a?

Select an option to see the answer and solution.

Which of this method is given parameter via command line arguments?

Select an option to see the answer and solution.

What will be the output of the following Java snippet, if attempted to compile and run this code with command line argument "java abc Ram Shyam"?
public class abc
{
	int a=2000;
        public static void main(String argv[])
        {
	    System.out.println(argv[1]+" :-Please pay Rs."+a);
        }
}

Select an option to see the answer and solution.

Which of these method of String class can be used to test to strings for equality?

Select an option to see the answer and solution.

What will be the output of the following Java program, Command line execution is done as - "java Output command Line 10 A b 4 N"?
class Output 
{
    public static void main(String args[]) 
    {
        System.out.print(args[6]);
    }
}

Select an option to see the answer and solution.

Which of these is a correct statement about args in the following line of code?
public static void main(String args[])

Select an option to see the answer and solution.

Which of these method of String class is used to obtain character at specified index?

Select an option to see the answer and solution.

All the variables of interface should be?

Select an option to see the answer and solution.