inheritance key words?

Below are the key words for inheritance?

a)extends
b)implements
c)both.

This is asked in my java test. I am little confused about this. Please give answer to this.

suresh
pnagasuresh1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
1) Extends is for classes, it means that this class extends (inherits from) another class...

2) implements is for interfaces, it means that this class MUST implement the methods prototyped in the Interface

The answer is A, as implements uses interfaces, which cannot themselves hold or manipulate data
0
pnagasuresh1Author Commented:
but if u declare a final varialbe in interface that will be inherited to the implimenting class.so why don't you say impliments is also keyword for inheritence.

suresh
0
girionisCommented:
> so why don't you say impliments is also keyword for inheritence.

  Because inherits means that you inherit the superclass' functionality, i.e. you can use superclass' functionality, while with implementation (as is the case with interfaces) you have to *define* your own implementation.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

girionisCommented:
 Well... I guess in a very strict "inheritance" term you coudl say that "implements" coudl be inheritance.
0
girionisCommented:
>  Well... I guess in a very strict "inheritance" term

  Sorry, I meant in a very *wide* "inheritance term.
0
functionpointerCommented:
>>> but if u declare a final varialbe in interface

pnagasuresh,
  Variables declared in an interface are by nature "final". You don't have to use the keyword 'final', and you don't have a choice. This is built in to 'interface'. give it a try. ;-)

And what about java.io.Serializable?  There is some implied functionality with certain interfaces that is built into the language. Although it may be a only in a very 'wide' term, inheritance it IS, nonetheless.

True, all an interface does is guarantee a signature, but that signature can imply an incredible amount of functionality, in and of itself.
0
pnagasuresh1Author Commented:
Dear functionpointer,

I could not understand what u said. Please explain more briefly.Till now I didn't get confident answer to my question.

suresh
0
functionpointerCommented:
with which part?

>> Variables declared in an interface are by nature "final"

public interface MyInterface {
   public static String VALUE= "blue";
   public MyInterface copy();
}

VALUE is final just because it is a variable in an interface, like it or not. You dont have to type the keyword "final", ( although you should ).

>> guarantee a signature...
If your class implements an interface, your class must have certain method signatures based on the interface. This means you can treat many subclasses the same if they all implement the same interface, because they will have common method signatures.

For example, using the above interface, you could have several classes the implement this interface. All would have the final String VALUE and none could change this. All would also have to implement the copy method and return a class that implements MyInterface.  Without even knowing the actual subclass, you could call the copy method on an instance and be absolutely sure the copy method not only existed, but returned an instance that implements MyInterface ( which would also have a final String VALUE of "blue" and a copy method you could call ).

In the case of java.io.Serializable, there are no member variables or methods in the interface. By implementing this empty interface, you are telling the VM that it can treat the class differently than other classes because you want serialization behavior (it's expensive and not always necessary, so its not implemented by default). In this case, you are giving a class 'parent' functionality, and isn't very different than a final method in a parent class.

Both extends and implements are inheritance keywords.

Does that make more sense?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.