This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie question

 
Tom Schuman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does implementing a method mean? Is it same as using it? Or is it to write a method in a class?

I speak finnish as my mother tongue and when i checked a English-Finish dictionary it says implement is same as a tool
[ February 24, 2005: Message edited by: Tom Schuman ]
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When ever any class implements an interface or when ever a non abstract class extends a abstract class, the class should implement ( in other words define ) the methods in the interface or define the abstract methods in the superclass.
ex:
 
Tom Schuman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it's basically adding statements to an empty method(abstract method?) so that it does something. Is it also called implementing when you write those statements when you make the method?
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Tom,

Before using a method (or simply call it), you must:

1 - Declare it : this states the method name, its input arguments and outpout return (and sometimes what exceptions it may throw).

2 - Define it : this express what the method really does using java syntax.

Interfaces declare methods but never define them. So basically, you can consider "implementing a method" as a synonym for "defining a method".

Hope that helps,
(By the way, I like very much Finland ! )
 
Tom Schuman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now i understand it
Thx alot Srinvasa and Linonel
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a few variations on the language for examples ...

ArrayList implements the List interface

ArrayList implements the size() method required by the interface

ArrayList is an implementation of List

An interface like List is "abstract"

An implementing class like ArrayList is "concrete" (unless it uses the "abstract" keyword)

As one of those lower life forms with only one language I admire all you folks who communicate in many. Never be afraid to ask what new things mean.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I may add my two cents, the word "to implement" also has another general meaning in programming. If you implement an algorithm or a method, it just means that you write the code for it.

Also, the dictionary you used is correct. The word "implement" can also be used as a noun to refer to any kind of tool. However, in this conversation, we are typically using the word as a verb instead.

Layne
 
Tom Schuman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an another question:

What do you exactly do when you override a method? I know it's something about changing what the method does.

Could someone give me a small code example where you first create a method and then override it? That would help me alot.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An overridden method is one that has a different implementation than a method of the same signature in the parent class.

For example, the code below defines a method in a base class, then an extended class inherits from that base class and overrides the method to do something else.

The interesting (and useful) thing about this is polymorphism: The method is invoked based on the true runtime type of the object. For example, if an extended object is upcast to its base type, the extended method will still be invoked...

(For more information, search the forums for "polymorphism.")
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic