Class, Objects and Interface - Object oriented programming (MCQ) questions

Here, you can read Class, Objects and Interface multiple choice questions and answers with explanation.

1)   Abstract class vs Interface
- Published on 19 Oct 15

a. A class may inherit only one abstract class but may inherit several interfaces.
b. An abstract class can provide complete and default code but an interface has no code
c. both a and b
d. none
Answer  Explanation 

ANSWER: both a and b

Explanation:
Abstract class and interface are generally confused to be the same but they are actually not the same. An abstract class cannot have its own instance but can have functions declared and defined inside it( normal functions). Abstract methods(functions) can only be declared inside an abstract class so in order to complete the functionality we need a subclass where the abstract functions can be defined(implemented). The functions which are only declared inside abstract class and not defined i.e. having incomplete functionality are written with keyword abstract and if an abstract class has only incomplete functions within then it is same as an Interface. Interface is not a class but an entity and it just has definition of functions with no implement ion. It is basically created to be overridden by implemented classes.


2)   An Abstract class
- Published on 19 Oct 15

a. allows normal method declaration within
b. can be instantiated
c. Must have abstract methods with implemetation within
d. none
Answer  Explanation 

ANSWER: allows normal method declaration within

Explanation:
Abstraction is the process of hiding implementation details and showing only functionality to the user. Classes that are declared with keyword abstract are called abstract classes. It cannot have any instances. It can carry normal functions declaration and definition along with abstract functions though the abstract methods(functions) cannot be defined inside the abstract class.For defining abstract methods subclasses are needed. Any class that extends the abstract class must implement all abstract methods declared by the super class.


1