Log In Register

Units


Interfaces - Questions and Answers

 

Practice these Interfaces under Java Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Interfaces for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Interfaces of Java Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge Java Programming specifically Interfaces.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Interfaces under Java Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Interfaces topic of Java Programming:

 

1. Given the following piece of code: public interface Guard{ void doYourJob(); } abstract public class Dog implements G uard{ } which of the following statements is correct?

Answer: Option D

Explanation:

2. Which two of the following are legal declarations for abstract classes and interfaces? 1. final abstract class Test {} 2. public static interface Test {} 3. final public class Test {} 4. protected abstract class Test {} 5. protected interface Test {} 6. abstract public class Test {}

Answer: Option D

Explanation:
(3), (6). Both are legal class declarations. (1) is wrong because a class cannot be abstract and final "there would be no way to use such a class". (2) is wrong because interfaces and classes cannot be marked as static. (4) and (5) are wrong because classes and interfaces cannot be marked as protected.

3. Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a default constructor. Which of the following is correct? 1. A a = new A(); 2. A a = new B(); 3. B b = new A(); 4. B b = new B();

Answer: Option B

Explanation:

4. Which of these statement is incorrect?

Answer: Option D

Explanation:
run() method is used to define the code that constitutes the new thread, it contains the code to be executed. start() method is used to begin execution of the thread that is execution of run(). run() itself is never used for starting execution of the thread.

5. Which of these access specifiers can be used for an interface?

Answer: Option A

Explanation:
Access specifier of interface is either public or no specifier. When no access specifier is used then default access specifier is used due to which interface is available only to other members of the package in which it is declared, when declared public it can be used by any code

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

Answer: Option C

Explanation:
interface is inherited by a class using implements.

7. Which of the following is a correct interface?

Answer: Option D

Explanation:

8. Which of these can be used to fully abstract a class from its implementation?

Answer: Option C

Explanation:

9.  Which of the following is incorrect statement about packages?

Answer: Option D

Explanation:
All methods and variables are implicitly public if interface is declared public.

10. What will be the output? interface A{ public void method(); } class One{ public void method(){ System.out.println("Cl ass One method"); } } class Two extends One implements A{ public void method(){ System.out.println("Cl ass Two method"); } } public class Test extends Two{ public static void main(String [] args){ A a = new Two(); a.method(); } }

Answer: Option B

Explanation:

11. Which of these keywords is used to define interfaces in Java?

Answer: Option A

Explanation:

12. Which of these method is used to begin the execution of a thread?

Answer: Option B

Explanation:

13. interface Test{ int p = 10; //line 1 public int q = 20; //line 2 public static int r = 30; //line 3 public static final int s = 40; //line 4 } Which of the above line will give compilation error?

Answer: Option D

Explanation:

14. Which of the following declares an abstract method in an abstract Java class?

Answer: Option B

Explanation:

15. Which of the following statements regarding abstract classes are true?

Answer: Option D

Explanation: