Results 1 to 10 of 10
Thread: having error with implements.
- 03-30-2011, 02:45 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 44
- Rep Power
- 0
having error with implements.
Okay I just started writing the code and i already got an error. I was wondering what i have to do to fix it.
Direction:You'll write SumGpa classes that implement the StudentStatisticCacluator interface,
to find the sum gpa in the student array passed to printStatistic.
Code:
public class SumGPA implements StudentStatisticCalculator {
}
(3) SumGPA.java:
error: SumGPA.java:1: SumGPA is not abstract and does not override abstract method print() in StudentStatisticCalculator
public class SumGPA implements StudentStatisticCalculator {
- 03-30-2011, 03:12 AM #2
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 8
-
- 03-30-2011, 04:19 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 44
- Rep Power
- 0
thanks fubarable, after reading it from the book, I am still confuse. About the method interface.
Instruction :You'll write Sum classes that implement the StudentStatisticCacluator interface,
to find the sumgpa in the student array passed to printStatistic.
public class SumGPA implements StudentStatisticCalculator {
public abstract GetSumGpa();
return gpa;
}
Error:
SumGPA.java:5: invalid method declaration; return type required
public abstract GetSumGpa();
^
SumGPA.java:6: illegal start of type
return gpa;
^
SumGPA.java:6: ';' expected
return gpa;
^
3 errors
- 03-30-2011, 04:50 AM #5
Oh come on. What part of "return type required" do you not understand? All methods have a return type: void, String, Foo etc.
Who told you to use the keyword "abstract"? An Interface has abstract methods by default. If your class is going to implement an Interface then your class needs to have fully implemented methods that match the signature of the methods in the Interface.
- 03-30-2011, 05:01 AM #6
Member
- Join Date
- Mar 2011
- Posts
- 44
- Rep Power
- 0
junky, im a college student im not too good with java at the moment
- 03-30-2011, 05:34 AM #7
Member
- Join Date
- Mar 2011
- Posts
- 44
- Rep Power
- 0
im still lost reallyy
- 03-30-2011, 05:34 AM #8
So exercise your brain. It seems to me like so many others starting out, you are just guessing. Very simple. Complete the code below by filling in the dots so it outputs 2. (without hard coding it)
Java Code:interface Incrementer { public int addOne(int value); } class MathLab implements Incrementer { .... public static void main(String[] args) { MathLab ml = new MathLab(); System.out.println(....); } }
- 03-30-2011, 05:47 AM #9
Member
- Join Date
- Mar 2011
- Posts
- 44
- Rep Power
- 0
Well this is what i have for coding:
public class SumGpa implements StudentStatisticCalculator {
interface SumGpa {
public double addOne(double value);
}
class SumGpa implements SumGpa {
return gpa;
public static void main(String[] args) {
SumGpa1 sl = new double gpa();
System.out.println(Gpa);
}
}
HAve the following error:
SumGPA.java:8: illegal start of type
return gpa;
^
SumGPA.java:8: ';' expected
return gpa;
^
SumGPA.java:11: '[' expected
SumGpa1 sl = new double gpa();
^
SumGPA.java:11: ']' expected
SumGpa1 sl = new double gpa();
^
SumGPA.java:14: reached end of file while parsing
}
- 03-30-2011, 05:58 AM #10
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 12
You really need to check your textbook, the sun tutorials, or talk to your teacher.
An interface is sort of an outline. None of the methods in it have a body, when you implement an interface it is your responsibility to make sure every method in the implemented interface is inplemented in this class.
If you have an interface x with three methods, a, b, and c and then you create a class called y and make it implement x you must define a, b, and c inside of y.
Don't just post the compiler errors here. Think about them and examine the lines generating them, try to figure it out yourself, it will be a great learning experience. All the compiler messages usually do a good job of explaining the error.
I want you to read the section in your text book on interfaces, then read the tutorials. Finally, I want you to explain your understanding of them to me.
Similar Threads
-
subclass that implements
By speedycerv in forum New To JavaReplies: 1Last Post: 03-30-2011, 01:11 AM -
What does IMPLEMENTS mean?
By nikkka in forum New To JavaReplies: 3Last Post: 03-07-2011, 11:21 AM -
Interface and implements
By Bored2 in forum New To JavaReplies: 27Last Post: 11-10-2010, 01:08 PM -
implements
By danghieu in forum New To JavaReplies: 1Last Post: 04-29-2010, 05:52 PM -
HashSet and AbstractSet both Implements Set
By rkjsohi2 in forum New To JavaReplies: 1Last Post: 08-07-2008, 11:04 AM
Bookmarks