This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Quick question about interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Quick question about interfaces" Watch "Quick question about interfaces" New topic

Quick question about interfaces

Rick Katka

Joined: Feb 22, 2004
Posts: 7
I'm implementing a textparsing application. My questions arises that if I have an interface class called DocumentComponent and it contains an ArrayList of components that are initialized in the constructor and a few methods such as add, remove, and count.
Will I be able to use the ArrayList of components in the overloaded classes such as sentence and word?
Thanks in advance!
Rick J. Katka
Rikko Verrijzer
Ranch Hand

Joined: Jul 22, 2003
Posts: 34
Hi Rick,
If you define an inteface you should know that all variables defined in that interface are final. That means that you can use the values(!!!), but not change them.
note that a value is something different for an object than for a primitive. Primitives values of those like int, byte, boolean etc. are unchangable. However, a object value is the refference to an object, not its inner values. This means that an object can not be replaced with any other reference, but its methods like add(), get(), count() etc. can be called and used to change its inner values.
So its possible to add new elements into your arraylist even though your arraylist is final. However you can't replace the arraylist with a new instance (filled with whatever you like).

Hope this helps?
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Will I be able to use the ArrayList of components in the overloaded classes such as sentence and word?
What do you mean by "overloaded class"?

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Quick question about interfaces
It's not a secret anymore!