search
Log In
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
2 votes
810 views

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. a is true
    2. b is true
    3. Both a and b are true
    4. Neitehr a nor b are true
in Object Oriented Programming
recategorized
810 views

1 Answer

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

2 votes
2 answers
1
1.2k views
Which of the following is used to make an Abstract class? Making at least one member function as pure virtual function Making at least one member function as virtual function Declaring as Abstract class using virtual keyword Declaring as Abstract class using static keyword
asked Aug 9, 2016 in Object Oriented Programming jothee 1.2k views
1 vote
1 answer
2
530 views
Match the following with reference to object oriented modelling: ... $a-iii, b-iv, c-ii, d-i$ $a-iii, b-i, c-ii, d-iv$ $a-iv, b-iii, c-ii, d-i$
asked Aug 10, 2016 in Object Oriented Programming jothee 530 views
1 vote
2 answers
3
876 views
Consider the following two statements: A publicly derived class is a subtype of its base class Inheritance provides for code resuse Which of the following statements is correct? Both statements a and b are correct Neither of the statements a and b are correct Statement a is correct and b is incorrect Statement a is incorrect and b is correct
asked Aug 8, 2016 in Object Oriented Programming jothee 876 views
0 votes
1 answer
4
125 views
Abstraction and encapsulation are fundamental principles that underlie the object oriented approach to software development. What can you say about the following two statements? Abstraction allows us to focus on what something does without considering the complexities of how it works. Encapsulation ... us. Neither I nor II is correct Both I and II are correct Only II is correct Only I is correct
asked Mar 24 in Object Oriented Programming jothee 125 views
...