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

4/7

Page

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

What is true of final class?

Select an option to see the answer and solution.

Which of these cannot be declared static?

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 "hello there"?
public class abc
{
    String[] xyz;
 
    public static void main(String argv[])
    {
        xyz=argv;
    }
 
    public void runMethod()
    {
        System.out.println(argv[1]);
    }
}

Select an option to see the answer and solution.

How many copies of static and class variables are created when 10 objects are created of a class?

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.

Can a class be declared with a protected modifier.

Select an option to see the answer and solution.

What will be the output of the following Java code snippet running with "java demo I write java code"?
public class demo
{
   public static void main(String args[])
   {
        System.out.println(args[0]+""+args[args.length-1]);
   }
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
class equality 
{
    int x;
    int y;
    boolean isequal()
    {
        return(x == y);  
    } 
}    
class Output 
{
    public static void main(String args[]) 
    {
        equality obj = new equality();
        obj.x = 5;
        obj.y = 5;
        System.out.println(obj.isequal);
    } 
}

Select an option to see the answer and solution.

What happens if constructor of class A is made private?

Select an option to see the answer and solution.

Which of the following modifier means a particular variable cannot be accessed within the package?

Select an option to see the answer and solution.

Which of these methods must be made static?

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 arr[] = {1, 2, 3, 4, 5};
        for ( int i = 0; i < arr.length - 2; ++i)
            System.out.println(arr[i] + " ");
    } 
}

Select an option to see the answer and solution.

What is the process of defining more than one method in a class differentiated by parameters?

Select an option to see the answer and solution.

How can a protected modifier be accessed?

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 = "I LIKE JAVA";   
        System.out.println(obj.length());
    }
}

Select an option to see the answer and solution.

Which of these keywords is used to prevent content of a variable from being modified?

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() 
    {
        volume = width * height * length;
    } 
    void volume(int x) 
    {
        volume = x;
    }
}    
class Output 
{ 
    public static void main(String args[]) 
    {
        box obj = new box();
        obj.height = 1;
        obj.length = 5;
        obj.width = 5;
        obj.volume(5);
        System.out.println(obj.volume);        
    } 
}

Select an option to see the answer and solution.

How do we pass command line argument in Eclipse?

Select an option to see the answer and solution.

Which is the modifier when there is none mentioned explicitly?

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.