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

3/16

Page

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

interface Base{
      boolean m1 ();
      byte m2(short s);
}

which two code fragments will compile?
1. interface Base2 implements Base {}

2. abstract class Class2 extends Base
    { public boolean m1(){ return true; }}

3. abstract class Class2 implements Base {}

4. abstract class Class2 implements Base
    { public boolean m1(){ return (7 > 4); }}

5. abstract class Class2 implements Base
    { protected boolean m1(){ return (5 > 7) }}

Select an option to see the answer and solution.

Which two of the following are legal declarations for abstract classes and interfaces?
1. final abstract class Test {}
2. public static interface Test {}
3. final public class Test {}
4. protected abstract class Test {}
5. protected interface Test {}
6. abstract public class Test {}

Select an option to see the answer and solution.

interface Test{
      int p = 10; //line 1
      public int q = 20; //line 2
      public static int r = 30; //line 3
      public static final int s = 40; //line 4
}

Which of the above line will give compilation error?

Select an option to see the answer and solution.

What will happen after compiling this program code?
abstract class MyClass{ //line 1
      private int a, b;

      public void call(int a, int b){
            this.a = a;
            this.b = b;
            System.out.print(a+b);
      }
}

public class Test{
      public static void main(String args[]){
            MyClass m = new MyClass(); //line 2
            m.call(12,25);
      }
}

Select an option to see the answer and solution.

Runnable is a _____ .

Select an option to see the answer and solution.

What is the output for the below code?
interface A{
      public void printValue();
}

public class Test{
      public static void main (String[] args){
            A a1 = new A(){
                         public void printValue(){
                               System.out.println("A");
                         }
                   };
            a1.printValue();
      }
}

Select an option to see the answer and solution.

What will be the output?
public interface InfA{
      protected String getName();
}

public class Test implements InfA{
      public String getName(){
            return "test-name";
      }
      public static void main (String[] args){
            Test t = new Test();
            System.out.println(t.getName());
      }
}

Select an option to see the answer and solution.

What will be the output for the below code?
public interface TestInf{
      int i =10;
}

public class Test{
      public static void main(String... args){
            TestInf.i=12;
	    System.out.println(TestInf.i);
      }
}

Select an option to see the answer and solution.

What will be the output when the following program is compiled and executed?
abstract class TestAbstract{
      String my_name;
      String myName(){
            my_name = "Examveda";
            return my_name;
      }
      abstract void display();
}

public class Test extends TestAbstract{
      void display(){
            String n = myName();
	    System.out.print("My name is "+ n);
      }

      public static void main(String args[]){
            Test t = new Test();
	    t.display();
      }
}

Select an option to see the answer and solution.

What happens if the following program is compiled and executed?
interface MyInterface{
      void display();
}

interface MySubInterface extends MyInterface{
      void display();
}

public class Test implements MySubInterface{
      public void display(){
            System.out.print("Welcome to Examveda.");
      }
      public static void main(String args[]){
            Test t = new Test();
	    t.display();
      }
}

Select an option to see the answer and solution.

Which object Java application uses to create a new process?

Select an option to see the answer and solution.

Which of these method of Double wrapper can be used to check whether a given value is infinite or not?

Select an option to see the answer and solution.

What will be the output of the following Java program?
interface calculate 
{
            int VAR = 0;
            void cal(int item);
}
        class display implements calculate 
        {
            int x;
          public  void cal(int item)
          {
                if (item<2)
                    x = VAR;
                else
                    x = item * item;            
            }
        }
 class interfaces 
{
 
            public static void main(String args[]) 
            {
                display[] arr=new display[3];
 
               for(int i=0;i<3;i++)
               arr[i]=new display();
               arr[0].cal(0);    
               arr[1].cal(1);
               arr[2].cal(2);
               System.out.print(arr[0].x+" " + arr[1].x + " " + arr[2].x);
            }
}

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, 2,3 , 4, 5};
            for (int i = 0; i < 5; ++i) 
                System.out.print(a[i]);
            int x = 1/0;
        }
        catch(ArrayIndexOutOfBoundsException e) 
        {
      System.out.print("A");        	
        }
        catch(ArithmeticException e) 
        {     	
            System.out.print("B");
        }
    }
}

Select an option to see the answer and solution.

Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?

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, 2,3 , 4, 5};
            for (int i = 0; i < 7; ++i) 
                System.out.print(a[i]);
        }
        catch(ArrayIndexOutOfBoundsException e) 
        {
      System.out.print("0");        	
        }
    }
}

Select an option to see the answer and solution.

Which of these method of InputStream is used to read integer representation of next available byte input?

Select an option to see the answer and solution.

The same import package/class be called twice in java?

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[])
    {
        System.exit(5);
    }
}

Select an option to see the answer and solution.

What type of variable can be defined in an interface?

Select an option to see the answer and solution.