简体   繁体   中英

Interfaces and abstract classes

Which is not true about interfaces and Abstract classes? (at least mark two answers)

a. Abstract class support to the inheritance relationship but not realization relationship.

b. Interface supports to the realization relationship but not inheritance relationship.

c. Both Abstract class and Interface are supporting inheritance relationship.

d. All above statements are correct.

I am little bit confused about the answer can any one help me.My guess is a,b,d

The question you've been set is so badly worded it can't have any sensible correct answer without further definition. As others have pointed out, option (d) brings about logical inconsistencies. Putting that aside though, the question remains ambiguous at best.

Inheritance and Realisation are binary relationships. There's no single answer therefore to whether Abstract Classes or Interfaces 'support' them. Instead, you have to ask: what roles in each relationship (Inheritance, Realisation) can each each classifier (Abstract Class, Interface) play? For the sake of simplicity, let's call the roles "parent" and "child" in both cases. Not semantically correct, but good enough for our purposes. For the avoidance of doubt though:

  • For inheritance: "parent" means the classifier inherited from, "child" means the inheriting classifier
  • For Realisation: "parent" means the classifier defining the specification, "child" means the classifier providing the realisation.

Finally, we need to define what "inheritance" and "realisation" mean. Since you've tagged this as java, we can assume "inheritance" means "extends" and "realisation" means "implements". However, that's a really questionable definition for Inheritance - which normally means implementation inheritance. Not the same semantics as Java's "extends".

OK. So now we can define a truth table for which roles each classifier can play.

               |  Inheritance  |   Realisation  |
               |parent | child | parent | child |
---------------|-------|-------|--------|-------| 
Abstract Class |   T   |   T   |    F   |   T   |
Interface      |   T   |   T   |    T   |   F   |
-------------------------------------------------

From that, we can see:

  1. Abstract Classes support both roles in the Inheritance relationship.
  2. Abstract Classes support only one role in Realisation relationship.

Note also that the table would be different if "inheritance" means "implementation inheritance" rather than "extends".

Let's now look at the options in your question

a. Abstract class support to the inheritance relationship but not realization relationship.

We can't say if that's true or false without defining what "support" means. Abstract classes support both Inheritance roles, so we can state the first clause is true. However they only support one Realisation role. So does that mean they do or don't support it? There's no answer unless "support" is explicitly defined as either "fully support" - both roles - or "partial support" - at least one role.

There's similar ambiguity for option (b) in your list.

Option (c) is however decidable. Interfaces and Abstract Classes both support both Inheritance roles therefore (c) is true. Note that if "inheritance" means "implementation inheritance" rather than "extends" however, then (c) is false.

In conclusion: without proper definition of the problem it's not possible to answer.

hth.

oh memories... is this for the java certified programmer?

a. true
b. false
c. true
d. wtf is correct? true or false? I think its... false

and you have to negate the answser...
check this out for more information about abstract classes and interfaces

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM