Interfaces


  1. AutoCloseable and Flushable are part of which package?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Autocloseable is a part of java.lang; Flushable is a part of java.io.


  1. Can “abstract” keyword be used with constructor, Initialization Block, Instance Initialization and Static Initialization Block.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    No, Constructor, Static Initialization Block, Instance Initialization Block and variables cannot be abstract.



  1. What is the output of this program?
    interface calculation
    {
    void calculate(int Num);
    }
    class display implements calculation
    {
    int p;
    public void calculate(int Num)
    {
    p = Num * Num;
    }
    }

    public class interfaces_Example
    {
    public static void main(String args[])
    {
    display object = new display();
    object.p = 0;
    object.calculate(4);
    System.out.print(object.p);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    16


  1. What is the output of this program?
    interface Calculation
    {
    void calculate(int item);
    }
    class display0 implements Calculation
    {
    int p;
    public void calculate(int num)
    {
    p = num * num;
    }
    }

    class display1 implements Calculation
    {
    int p;
    public void calculate(int num)
    {
    p = num / num;
    }
    }

    public class interfaces_Example
    {
    public static void main(String args[])
    {
    display0 object0 = new display0();
    display1 object1 = new display1();
    object0.p = 0;
    object1.p = 0;
    object0.calculate(5);
    object1.calculate(5);
    System.out.print(object0.p + " " + object1.p);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    class display0 implements the interface calculate by doubling the value of num, where as class display1 implements the interface by dividing num by num, therefore variable p of class display0 stores 25 and variable p of class display1 stores 1.



  1. What is the output of this program?
    interface Calculation 
    {
    int var = 0;
    void calculate(int num);
    }

    class display implements Calculation
    {
    int p;
    public void calculate(int num)
    {
    if (num<2)
    {
    p = var;
    }
    else
    {
    p = num * num;
    }
    }
    }

    public class interfaces_Example
    {

    public static void main(String args[])
    {
    display[] array = new display[4];

    for(int k=0; k<4; k++)
    array[k] = new display();
    array[0].calculate(0);
    array[1].calculate(2);
    array[2].calculate(4);
    System.out.print(array[0].p+" " + array[1].p + " " + array[2].p);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    0 4 16