First off, do you understand the differences between an abstract class
and an interface.
An abstract class defines a concept of what the implementing class is.
For example, if you have a concrete class that extends an abstract
class, you're basically saying that the concrete class IS A(n) abstract
class. (A ktichen IS A room - for a real life example.) An interface,
on the other hand, is a contract for your class. So, if a class
implements an interface, it is essentially saying that that class will
have certain abilities and characteristics, but will provide its own
implementation of those things. So, a car and a plane and a truck are
all vehicles (abstract) but they all implement the Driving interface.
This guarantees they can all drive, but each one does it in their own
way.
So, back to your question.
An abstract has the ability to implement some of its methods while
leaving others up to the concrete classes. As a result, an abstract
class will need variables to implement those methods. What scope those
variables have to the concrete classes depends on what you want to do
with that abstract class. The two you should generally look at,
though, are private variables (the only way to access is via
getter/setter methods within the abstract class) and protected
variables. Protected variables can be directly accessed by classes
that extend the abstract class. In the following example,
AbstractClass implements a method called "stuff()." Stuff uses a
variable called "text." Because text is protected, the implementing
class, "ConcreteClass" can access "text" directly without worrying
about getters/setters.
public abstract class AbstractClass() {
protected String text;
public String stuff() {
text = "Some Stuff";
return text;
}
public abstract String otherStuff();
}
public class ConcreteClass() extends AbstractClass {
public String otherStuff() {
text = "Some Other Stuff"; // text variable from AbstractClass
return text;
}
}
I hope I got all that correct (it's early still) and I hope that
explains things a little bit for you. Someone correct me if I messed
up in my explanation anywhere.