Vidyalelo
Java Programming · all questions

Interfaces and Abstract Classes
practice.

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

309

Questions

4/16

Page

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

How to use environment properties in the class?

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[])
    {
  String str = "true false";
        boolean x = Boolean.parseBoolean(str);
        System.out.print(x);
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
import java.io.*;
class files 
{
    public static void main(String args[]) 
    {
        File obj = new File("/java/system");
        System.out.print(obj.getName());
    }
}

Select an option to see the answer and solution.

Which of these is a super class of wrappers Byte and short wrappers?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class exception_handling 
{
    public static void main(String args[]) 
    {
        try 
         {
            int a = 1;
            int b = 10 / a;
            try 
            {
                 if (a == 1)
                     a = a / a - a;
                 if (a == 2) 
                 {
                     int c[] = {1};
                     c[8] = 9;
                 }
            finally 
            {
                System.out.print("A");
            }

        }
        catch (NullPointerException e) 
        {
                System.out.println("B");
        }
    }
}

Select an option to see the answer and solution.

Which of these access specifiers can be used for an interface?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.lang.reflect.*;
class Additional_packages
{	 
     public static void main(String args[])
     {
   try
         {
       Class c = Class.forName("java.awt.Dimension");
 Constructor constructors[] = c.getConstructors();
 for (int i = 0; i < constructors.length; i++)
     System.out.println(constructors[i]);
   }
   catch (Exception e)
         {
               System.out.print("Exception");
         }
    }
}

Select an option to see the answer and solution.

Which of the following package stores all the standard java classes?

Select an option to see the answer and solution.

What type of methods an interface contain by default?

Select an option to see the answer and solution.

Which of these exceptions is thrown by compareTo() method defined in a double wrapper?

Select an option to see the answer and solution.

Which of these methods is used to check for infinitely large and small values?

Select an option to see the answer and solution.

What is true about the setProperties method?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.io.*;
class Chararrayinput 
{
    public static void main(String[] args) 
    {
  String obj  = "abcdef";
        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, 0, 3);
        int i;
        try 
        {
while ((i = input1.read()) != -1) 
            {
                System.out.print((char)i);
            }
        } 
        catch (IOException e) 
        {
      // TODO Auto-generated catch block
            e.printStackTrace();
  }
}
}

Select an option to see the answer and solution.

Java system properties can be set at runtime.

Select an option to see the answer and solution.

What will be the output of the following Java code?
class Output 
{
    public static void main(String args[]) 
    {
        byte a[] = { 65, 66, 67, 68, 69, 70 };
        byte b[] = { 71, 72, 73, 74, 75, 76 };  
        System.arraycopy(a, 2, b, 1, a.length-2);
        System.out.print(new String(a) + " " + new String(b));
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program? (Note: file is made in c drive.)
import java.io.*;
class files 
{
    public static void main(String args[]) 
    {
        File obj = new File("/java/system");
        System.out.print(obj.getAbsolutePath());
    }
}

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[])
    {
        String str = "true";
        boolean x = Boolean.valueOf(str);
        System.out.print(x);
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program? (Note: file is made in c drive.)
import java.io.*;
class files 
{
    public static void main(String args[]) 
    {
        File obj = new File("/java/system");
        System.out.print(obj.canWrite());
        System.out.print(" " + obj.canRead());
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
public class BoxDemo
{
    public static <U> void addBox(U u, 
    java.util.List<Box<U>> boxes)
    {
       Box<U> box = new Box<>();
       box.set(u);
       boxes.add(box);
    }
    public static <U> void outputBoxes(java.util.List<Box<U>> boxes) 
    {
        int counter = 0;
        for (Box<U> box: boxes) 
        {
            U boxContents = box.get();
            System.out.println("[" + boxContents.toString() + "]");
            counter++;
        }
    }
    public static void main(String[] args)
    {
        java.util.ArrayList<Box<Integer>> listOfIntegerBoxes = new java.util.ArrayList<>();
        BoxDemo.<Integer>addBox(Integer.valueOf(0), listOfIntegerBoxes);
        BoxDemo.outputBoxes(listOfIntegerBoxes);
    }
}

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[]) 
    {
        Integer i = new Integer(257);  
        float x = i.floatValue();
        System.out.print(x);
    }
}

Select an option to see the answer and solution.