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

11/16

Page

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

Which of these methods initiates garbage collection?

Select an option to see the answer and solution.

What will be the output of the following Java program? (Note: inputoutput.java is stored in the disk.)
import java.io.*;
class filesinputoutput 
{
    public static void main(String args[]) 
    {
        InputStream obj = new FileInputStream("inputoutput.java");
        System.out.print(obj.available());
    }
}

Select an option to see the answer and solution.

Which of these methods return a class object given its name?

Select an option to see the answer and solution.

Which of the following 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?
interface calculate
{
    void cal(int item);
}
class displayA implements calculate
{
    int x;
    public void cal(int item)
    {
        x = item * item;            
    }
}
class displayB implements calculate
{
    int x;
    public void cal(int item)
    {
        x = item / item;            
    }
}
class interfaces 
{
    public static void main(String args[])
    {
        displayA arr1 = new displayA;
        displayB arr2 = new displayB;
        arr1.x = 0;
        arr2.x = 0;      
        arr1.cal(2);
        arr2.cal(2);
        System.out.print(arr1.x + " " + arr2.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.getParent());
        System.out.print(" " + obj.isFile());
    }
}

Select an option to see the answer and solution.

Which of these class is used to make a thread?

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[])
    {
        Double y = new Double(257.57812);
  Double i = new Double(257.578123456789);  
        try
        {
      int x = i.compareTo(y);
            System.out.print(x);
        }
        catch(ClassCastException e)
        {
            System.out.print("Exception");
        }
}
}

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("Box #" + counter + " contains [" + boxContents.toString() + "]");
            counter++;
        }
    }
    public static void main(String[] args)
    {
        java.util.ArrayList<Box<Integer>> listOfIntegerBoxes = new java.util.ArrayList<>();
        BoxDemo.<Integer>addBox(Integer.valueOf(10), listOfIntegerBoxes);
        BoxDemo.outputBoxes(listOfIntegerBoxes);
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.util.*;
class LOCALE_CLASS
{
    public static void main(String args[])
    {
        Locale obj = new Locale("HINDI", "INDIA") ;
        System.out.print(obj.getCountry());
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.lang.System;
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, 3, a.length - 4);
        System.out.print(new String(a) + " " + new String(b));
    }
}

Select an option to see the answer and solution.

Does code Segment loads the java code?

Select an option to see the answer and solution.

Which of the following is a method of wrapper Float for converting the value of an object into byte?

Select an option to see the answer and solution.

Which of these Exceptions is thrown by loadClass() method of ClassLoader class?

Select an option to see the answer and solution.

Which of these interface is not a member of java.io package?

Select an option to see the answer and solution.

Which of these package is used for graphical user interface?

Select an option to see the answer and solution.

How to read a classpath file?

Select an option to see the answer and solution.

toRadian() and toDegree() methods were added by which version of Java?

Select an option to see the answer and solution.

Which of the following exceptions is thrown by every method of Runtime class?

Select an option to see the answer and solution.

Which of these is a method to clear all the data present in output buffers?

Select an option to see the answer and solution.