?
Solved

inheritance key words?

Posted on 2003-03-03
8
Medium Priority
?
226 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:pnagasuresh1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 8057988
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
 

Author Comment

by:pnagasuresh1
ID: 8058063
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
 
LVL 35

Expert Comment

by:girionis
ID: 8058619
> 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:girionis
ID: 8058643
 Well... I guess in a very strict "inheritance" term you coudl say that "implements" coudl be inheritance.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8058675
>  Well... I guess in a very strict "inheritance" term

  Sorry, I meant in a very *wide* "inheritance term.
0
 
LVL 2

Expert Comment

by:functionpointer
ID: 8061992
>>> 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
 

Author Comment

by:pnagasuresh1
ID: 8065325
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
 
LVL 2

Accepted Solution

by:
functionpointer earned 60 total points
ID: 8065977
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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question