given the superClass I can write driver programs to run correctly. I can even employ some intermediate techniques, given the time I have been programming.My problem occurred when I was asked to write a class for someone else's driver. here is the Driver I was asked to write a class for.
You should also familiarize yourself with static methods. They come in handy when you need to incorporate Singleton classes in your software architecture -- connection pooling etc.
Google static methods Java Tutorial to add to it.
publicclass ClassA{
ClassX var;
publicvoid method1(ClassX var){
this.var = var;
//do some operation on var
}
public ClassX method2(){
returnnew ClassX();
}
publicstaticvoid method3(ClassX var){
// perform some operation
}
}
// when using ClassA
ClassA varA = new ClassA();
ClassX varX = new ClassX();
varX.performSomeOperationToSetPropertiesInX();
varA.method1(varX);
// You can do this in your main class
// To perform method3 so as to alter another property in varX you
// can do:
ClassA.method3(varX);
The object varX now has undergone some property change. I don't know if this actually makes sense, but that's my lame attempt at a try.
Thanks for all of your help. I understand your confusion I didn't know exactly how to ask the question until someone responded. Now I can Say That my College prof wants us to write the main class to run a pre-written driver program from the book. sort of like the String Class has CharAt(),indexOf()etc... mine will need to have a getName() getAnnualSalary() etc...included. Hope this helps explain my dilema.
P.S. I Think my prof needed to teach this first then the other would have been a piece of cake.
publicclass Main {
public Main() {
//do something important
public Main(...some prameters...) {
//do something important
}
}
public String getName() {
//do something important
}
publicdouble getAnnualSalary() {
//do something important
}
//if should be executable
publicstaticvoid main (String[]args) {
new Main();
//do something important
}
privatedouble a_variable;
private String another variable;
}
neumi Thanks for your help. Just to let you know I did research this topic and Javaranch.com, Sun, and others seem to think if you have gotten far enough to be looking for answers to this question you should be able to figure it out on your own. I couldn't find anything relating to classes that would help me with this problem. that is why I came here where I could ask a question and get multiple responses to relate to.
A class simply represents an Object. Objects have attributes and methods.
You should consider reading something about object oriented programming. The rest is just syntax.
If you want to do it right, close down Netbeans right now and try to define your class/object on a piece of paper. Write down all it's attributes and public methods with a definition of input and output.