I am very poor when it comes to programming, but trying really hard to pass my exam, I have two quick questions I hope someone can answer for me please....
Implement the method sum that gives summation of the passed array. ie; the array has five elements 1,2,3,4,5, then 15 should be returned.
and I have been trying to practice some code but keep getting errors.....
public class DebugTest3 { public static void main (String args[]) { One oneVar= new One(); int answer = oneVar.getResult(10); System.out.println("Answer=" +answer);
public abstract class One() { public abstract void displayResult(int result); public int getResult(int num) { return 2 * num; }}
Anyone's help is greatly appreciated..... Nobel...
Since the class One is abstract, you can not instantiate it. But you can extend it and provide a non abstract or concrete implementation of the displayResult method.
publicclass DebugTest3 extends One{
publicstaticvoid main (String args[]){
DebugTest3 oneVar= new DebugTest3();
int answer = oneVar.getResult(10);
oneVar.displayResult(answer);
}
publicvoid displayResult(int result){
System.out.println("Answer = " + String.valueOf(result));
}
}
Sorry to bug you again, but I ran the code and got errors
C:\Java\DebugTest3.java:7: cannot resolve symbol symbol : class one location: class DebugTest3 public class DebugTest3 extends One{ ^ C:\Java\DebugTest3.java:12: cannot resolve symbol symbol : method getResult (int) location: class DebugTest3 int answer = oneVar.getResult(10); ^ 2 errors