Syntax error on token "extends", throws expected
I have made this subclass:
Code :
public static void cacluate() extends readResearchfile {
//
}
But it gives me this error: Syntax error on token "extends", throws expected
If I add throws IOException behind the exteds readResearchfile it says I should deleate exteds readResearchfile.
How do I get this to work?
I can read erroros but I don't understand this one. :(
Re: Syntax error on token "extends", throws expected
A method cannot extend a class, only a class can extend a class or an interface can extend an interface
Code :
public class MyClass extends SomeClass { }
public class MyClass implements SomeInterface { }
public interface MyInterface extends SomeInterface { }
Re: Syntax error on token "extends", throws expected
Hello Purple01!
Quote:
Originally Posted by
Purple01
I have made this subclass:
Code :
public static void cacluate() extends readResearchfile {
//
}
As I can see cacluate is as method and you are treating it like a class.
If cacluate is supposed to be a class that extends readResearchfile(supposingly this is a class too), then you have wrong syntax.
If it's a method then what you are trying is completely wrong - a method cannot extend anything (either a class or a method).
Can you describe what are you trying to do?
Re: Syntax error on token "extends", throws expected
The thing is I have a file that I read line by line (in the class readResearchfile)
But I have to make the same calulation over and over again for certain parts, and in diffrent loops.
So I was planning on putting that calculations part in a new subclass and just print calculate(); to run the calculations.
It would make my code much more better to understand.
And then I also don't have the same code printed like 11 times.
This is the readResearchfile() class:
Code :
public static void readResearchfile() throws FileNotFoundException {
cacluate();
}
I will have a look at these class / method things agan. :)
Re: Syntax error on token "extends", throws expected
I solved it.
I used the subclass whitout the extends.
So public static void calculate() {
And then I would let the program run that subclass when het needs to calculate something.
And it works. :)
Thanks everyone.