Site icon DataFlair

Quiz on Interface in Java

quiz on interface in java

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

In the realm of object-oriented programming with Java, interfaces reign supreme as foundational building blocks. Think of them as blueprints, meticulously outlining the behaviors (methods) that classes must adhere to. This elegant approach fosters code reusability – imagine crafting reusable building blocks for your programs! It also promotes loose coupling, where classes collaborate without relying on intricate details of each other’s inner workings.

Finally, interfaces champion polymorphism, the ability for objects of different classes to respond to the same method call in unique ways. But how well-versed are you in the intricacies of Java interfaces?

Dive into this interactive quiz and put your knowledge to the test! This comprehensive assessment will delve into various aspects of interfaces, including abstract methods – the core functionalities a class must provide – access modifiers that dictate visibility and control, and even explore how interfaces enable a form of multiple inheritance, a powerful technique for incorporating functionalities from multiple sources.

So, are you ready to embark on this exciting challenge and solidify your understanding of Java interfaces? Let’s test your knowledge.

Time limit: 0

Quiz Summary

0 of 15 Questions completed

Questions:

Information

You have already completed the quiz before. Hence you can not start it again.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

     Which of the following is not true about interfaces ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    interface Interface {

    public void method1();

    public void method2();

    }

    class InterfaceSample implements Interface {

    public void method1() {

    System.out.println(“Method is executed”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    InterfaceSample i = new InterfaceSample();

    i.method1();

    }

    }

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

     interface sample {

    public void print();

    }

    class Demo implements Sample {

    Public void print() {

    System.out.println(“DataFlair”);

    }

    }

    class Example extends Demo {

    public void display() }

    System.out.println(“Webservices”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Example e = new Example();

    e.print();

    e.display();

    }

    }

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which access specifier must be used to declare classes in the interface ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

     interface  One {

    public void Get();

    public void Display();

    }

    class First implements One {

    public void Get() {

    Scanner sc = new Scanner(System.in);

    int variable = sc.nextInt();

    }

    public void Display() {

    System.out.println(a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    First f = new First();

    f.Get();

    f.Display();

    }

    }

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    interface Maths {

    public void Squareroot(int a);

    public void Area(int a);

    }

    class Calculate implements Maths {

    public void Squareroot(int a) {

    System.out.println(math.sqrt(a));

    }

    public void Area(int a) {

    System.out.println(a*a);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Maths m = new Maths();

    m.Squareroot(4);

    m.Area(4);

    }

    }

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which of the following is not achieved using the interface ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

    interface Methods {

    public void function();

    }

    class Calculate implements Methods {

    public void function ( int l , int b) 

    {

    int area = l * b;

    System.out.println(area);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    Calculate c = new Calculate();

    c.function(5,10);

    }

    }

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

     interface Example {

    final void function();

    }

    class First implements Example {

    final void function() {

    System.out.println(“Interface is implemented”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    First obj = new First();

    obj.function();

    }

    }

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of the following conditions raise an error while using interfaces ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

     interface A {

    int x = 10;

    }

    class B implements A {

    public void method() 

    {

    int x= x+5;

    System.out.println(x);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

        B b = new B();

    b.method();

    }

    }

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

    Which of the following keywords can be used to declare variables in Interfaces ?

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

     interface Demo {

    public void A();

    }

    class B implements Demo {

    public void A() 

    {

    System.out.println(“DataFlair”);

    }

    public void C()

    {

    System.out.println(“WebServices”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Demo d = new B();

    d.A();

    d.C();

    }

    }

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

     interface InterfaceDemo {

    String data = “DataFlair”;

    public void method(boolean a);

    }

    class Sample implements InterfaceDemo {

    public void method( boolean a) {

    if(a==true) {

    String value = data;

    System.out.println(value);

    }

    else {

    System.out.println(“Method is not executed”);

    }

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Sample s = new Sample();

    s.method(false);

    }

    }

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    Which of the following is the correct syntax of an Interface in Java ?

    Correct
    Incorrect

Summary:

Delving into the world of Java interfaces, this quiz presented you with 15 multiple-choice questions to test your knowledge of fundamental interface concepts.

By tackling these questions, you embarked on a journey of exploration, examining how to define abstract methods within interfaces, how to specify access modifiers for those methods, and how interfaces enable a form of multiple inheritance in Java and investigated how to implement interface methods in concrete classes, solidifying the connection between interfaces and practical application.

This quiz is designed to be a springboard for further learning, regardless of your final score. Whether you aced it or encountered some challenges, there’s always room for growth. Embrace the provided resources like online tutorials, courses, and forums to solidify your understanding of interfaces.

Remember, consistent practice is the key that unlocks mastery of Java interfaces. So, keep exploring, keep practising, and keep building your expertise in this essential aspect of Java programming.

Exit mobile version