0% found this document useful (0 votes)
128 views

Java Interface Quiz

This document contains a 10 question quiz about Java interfaces. The questions cover topics like the differences between interfaces and abstract classes, how classes implement interfaces using the implements keyword, the type of inheritance facilitated by interfaces, valid and invalid interface member types, the relationship between a class that implements an interface, errors in interface and class code, valid access specifiers for interfaces, whether interfaces can be declared final or contain constructors.

Uploaded by

Annu Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views

Java Interface Quiz

This document contains a 10 question quiz about Java interfaces. The questions cover topics like the differences between interfaces and abstract classes, how classes implement interfaces using the implements keyword, the type of inheritance facilitated by interfaces, valid and invalid interface member types, the relationship between a class that implements an interface, errors in interface and class code, valid access specifiers for interfaces, whether interfaces can be declared final or contain constructors.

Uploaded by

Annu Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Interface Quiz

Q1. Every thing that can be done by an abstract class, can be done by an Interface?

1. Yes
2. No

Q2. Which of these keywords is used by a class to use an interface defined previously?

1. import
2. Import
3. implements
4. Implements

Q3. What type of inheritance is facilitated by interfaces?

1. Feature Based
2. Role Based
3. Method Based

Q4. Which of the following can't be a member of an interface?

1. Constructors
2. Static Methods
3. Non Static Data Members
4. All of these

Q5. When a class A implements an interface B, what relation is created b/w them?

1. A is B
2. A has B
3. B is A
4. B has A

Q6. What is the error in the following code?


interface A {
int sum(int x,int y);
}
class B implements A{
int sum(int x,int y){
return (x+y);
}
}
A. In class, method sum() should be declared public.
B. In Interface, function should not end with ;
C. Int sum() can’t be written in class
D. In Interface, method sum() should be declared public.

Q7. Is this interface correct. If no,why?


public interface A{
void show(){
System.out.println("show");
};
}
A. It is correct
B. In Interface, function should not end with ;
C. Interface abstract methods can not have body
D. Interface can’t be public

Q8. Which access specifiers can interface use?


A. Protected
B. Public
C. Protected, Private
D. Public, Private, Protected

Q9. Can we declare interface as final.?


A. Yes
B. No, because then we will not be able to extend it.

Q10. Can interface contain a constructor?


A. No, because we cannot create object of interface.
B. Yes
C. No, because Interface is implemented by class

You might also like