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.  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.

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 the following declares an abstract method in an abstract Java class?

Answer: Option B

Explanation:

5. Runnable is a _____ .

Answer: Option C

Explanation:

6. What will be the output? 1. public interface InfA{ 2. protected String getName(); 3. } public class Test implements InfA{ public String getName(){ return "test-name"; } public static void main (String [] args){ Test t = new Test(); System.out.println(t.getName()); } }

Answer: Option B

Explanation:
Illegal modifier for the interface method InfA.getName(); only public and abstracts are permitted.

7. 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

8. Which of these interface is implemented by Thread class?

Answer: Option A

Explanation:

9. 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:

10.  Which of the following package stores all the standard java classes?

Answer: Option B

Explanation:

11. Which of the following is correct way of implementing an interface salary by class manager?

Answer: Option B

Explanation:

12. Given the following piece of code: public class School{ public abstract double numberO fStudent(); } which of the following statements is true?

Answer: Option D

Explanation:

13. What is the output for the below code ? interface A{ public void printValue(); } 1. public class Test{ 2. public static void main (String[] args){ 3. A a1 = new A(){ 4. public void printValue(){ 5. Syst em.out.println("A"); 6. } 7. }; 8. a1.printValue(); 9. } 10. }

Answer: Option B

Explanation:
The A a1 reference variable refers not to an instance of interface A, but to an instance of an anonymous (unnamed) class. So there is no compilation error.

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

Answer: Option C

Explanation:

15. What will happen after compiling this program code? abstract class MyClass{ //line 1 private int a, b; public void call(int a, int b){ this.a = a; this.b = b; System.out.print(a+b); } } public class Test{ public static void main(String a rgs[]){ MyClass m = new MyClass(); //line 2 m.call(12,25); } }

Answer: Option C

Explanation:
Abstract class is not concrete class which means object cannot be created for abstract class, its requires extending it and then create the object of extended class.