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

10/16

Page

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

Which of these classes can schedule task for execution in future?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class X 
{
    int a;
    double b;
}
class Y extends X 
{
int c;
}
class Output 
{
    public static void main(String args[]) 
    {
        X a = new X();
        Y b = new Y();
        Class obj;
        obj = b.getClass();
        System.out.print(obj.getSuperclass());
    }
}

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 x = 3.14;  
         int y = (int) Math.abs(x);
         System.out.print(y);
     }
}

Select an option to see the answer and solution.

Which of these methods is not defined in both Byte and Short wrappers?

Select an option to see the answer and solution.

Which of these methods is used to know whether a string contains "true"?

Select an option to see the answer and solution.

Which of the interface contains all the methods used for handling thread related operations in Java?

Select an option to see the answer and solution.

Which of these method is a rounding function of Math class?

Select an option to see the answer and solution.

Which of these is method for testing whether the specified element is a file or a directory?

Select an option to see the answer and solution.

Which of these methods calls update() method?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class newthread implements Runnable 
{
Thread t;
    newthread() 
    {
        t = new Thread(this,"My Thread");
        t.start();
}
public void run() 
    {
  System.out.println(t.getName());
}
}
class multithreaded_programing 
{
    public static void main(String args[]) 
    {
        new newthread();        
    }
}

Select an option to see the answer and solution.

Which of these values are returns under the case of normal termination of a program?

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 = args.length;
            int b = 10 / a;
            System.out.print(a);
            try 
            {
                 if (a == 1)
                     a = a / a - a;
                 if (a == 2) 
                 {
                     int c = {1};
                     c[8] = 9;
                 }
            }
            catch (ArrayIndexOutOfBoundException e) 
            {
                System.out.println("TypeA");
            }
            catch (ArithmeticException e) 
            {
                System.out.println("TypeB");
            }
    }
}

Note: Execution command line: $ java exception_handling one two

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 display implements calculate
{
    int x;
    public void cal(int item)
    {
        x = item * item;            
    }
}
class interfaces
{
    public static void main(String args[])
    {
        display arr = new display;
        arr.x = 0;      
        arr.cal(2);
        System.out.print(arr.x);
    }
}

Select an option to see the answer and solution.

What does an interface contain?

Select an option to see the answer and solution.

Math.random() guarantees uniqueness?

Select an option to see the answer and solution.

What will be the output of the following Java program?
package pkg;
class output 
{
    public static void main(String args[])
    {
        StringBuffer s1 = new StringBuffer("Hello World");
        s1.insert(6 , "Good ");
        System.out.println(s1);
    }
}

Note : Output.class file is not in directory pkg.

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.io.*;
public class filesinputoutput 
{
  public static void main(String[] args) 
    {
 String obj  = "abc";
       byte b[] = obj.getBytes();
       ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
       for (int i = 0; i < 2; ++ i) 
       {
           int c;
           while ((c = obj1.read()) != -1) 
           {
             if (i == 0) 
               {
                   System.out.print(Character.toUpperCase((char)c)); 
             }
           }
       }
    }
}

Select an option to see the answer and solution.

How to assign values to variable using property?

Options are not available for this question.

Select an option to see the answer and solution.

Which of these methods return string equivalent of Boolean object?

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[]) 
    {
        double x = 102;
        double y = 5;
        double z = Math.IEEEremainder(x, y);
        System.out.print(z);}
     }
}

Select an option to see the answer and solution.