setting attributes(variables) in an Abstract class
Hi All,
I have been reading about and playing with abstract classes and interfaces. I understand how the methods work with respect to implementing an interface or extending an abstract class. What I am trying to understand, though, is how the attributes (or variables) work when extending an abstract class.
For example, lets say I have an abstract class that contains undefined variables. Can I set those variables within the class that is extending the abstract class without using a public method? How would that work, or is it unreasonable to declare variables in a abstract class without giving them values within that class?
Example Code:
Code:
abstract class Setup extends JInternalFrame{
String programName;
JPanel[] panels;
String[] panelTitles;
public Setup() {
//... code that creates the JInternalFrame, etc...
// ...instantiates a JTabbedPane and a JScrollPane...
}
public void addPanels (JPanels[] panels) {
//...code to add the panels to a JTabbedPane within the JInternalFrame...
}
}
public class ExampleProgram extends Setup {
public ExampleProgram() {
// ... I want define the programName, Panels it uses, and the panel
// titles here, but I am not sure how ...
}
}
I did create a public "setter" method within the abstract class and called that method within the ExampleProgram class and that did work... but I don't want that variable open to being set from outside the ExampleProgram class.
Anyone have any good tutorial links, books, ideas, suggestions... ?
Thanks in advance for any help!!
Chris