edited by
4,565 views
2 votes
2 votes

Which of the following is/are correct with reference to Abstract class and interface?

  1. A class can inherit only one Abstract class but may inherit several interfaces
  2. An abstract class can provide complete and default code but an interface has no code
    1. i is true
    2. ii is true
    3. Both i and ii are true
    4. Neitehr i nor ii are true
edited by

1 Answer

2 votes
2 votes

ans is C 

An interface is an empty shell, there are only the signatures of the methods, which implies that the methods do not have a body. The interface can't do anything. It's just a pattern so b is true

he key technical differences between an abstract class and an interface are:

  • Abstract classes can have constants, members, method stubs (methods without a body) and defined methods, whereas interfaces can only have constants and methods stubs.

  • Methods and members of an abstract class can be defined with any visibility, whereas all methods of an interface must be defined as public (they are defined public by default).

  • When inheriting an abstract class, a concrete child class must define the abstract methods, whereas an an abstract class can extend another abstract class and abstract methods from the parent class don't have to be defined.

  • Similarly, an interface extending another interface is not responsible for implementing methodsfrom the parent interface. This is because interfaces cannot define any implementation.

  • A child class can only extend a single class (abstract or concrete), whereas an interface can extend or a class can implement multiple other interfaces so a is true

  • A child class can define abstract methods with the same or less restrictive visibility, whereas a class implementing an interface must define the methods with the exact same visibility (public).

Answer:

Related questions

1 votes
1 votes
1 answer
2
go_editor asked Aug 10, 2016
1,294 views
Match the following with reference to object oriented modelling :$\begin{array}{clcl} & \textbf{List-I} && \textbf{List-II} \\ \text{(a)} & \text{Polymorphism} & \text{(...
3 votes
3 votes
2 answers
4
go_editor asked Aug 1, 2016
3,695 views
Which one of the following is correct?Java applets cannot be written in any programming languageAn applet is not a small programAn applet can be run on its ownApplets are...