Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

inheritance key words?

Posted on 2003-03-03
8
Medium Priority
?
229 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

581 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