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.
Which of the following is not true about interfaces ?
Correct
Incorrect
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
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
Question 4 of 15
4. Question
Which access specifier must be used to declare classes in the interface ?
Correct
Incorrect
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
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
Question 7 of 15
7. Question
Which of the following is not achieved using the interface ?
Correct
Incorrect
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
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
Question 10 of 15
10. Question
Which of the following conditions raise an error while using interfaces ?
Correct
Incorrect
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
Question 12 of 15
12. Question
Which of the following keywords can be used to declare variables in Interfaces ?
Correct
Incorrect
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
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
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.
Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google
DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.