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