Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Syntax error on token "extends", throws expected

  1. #1
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Syntax error on token "extends", throws expected

    I have made this subclass:

    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.


  2. #2
    Junior Member
    Join Date
    Mar 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

    public class MyClass extends SomeClass { }
    public class MyClass implements SomeInterface { }
    public interface MyInterface extends SomeInterface { }

  3. #3
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Syntax error on token "extends", throws expected

    Hello Purple01!

    Quote Originally Posted by Purple01 View Post
    I have made this subclass:
    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?

  4. #4
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default 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:

    public static void readResearchfile() throws FileNotFoundException {
         cacluate(); 
    }

    I will have a look at these class / method things agan.

  5. #5
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default 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.

Similar Threads

  1. Syntax error on token ";", { expected after this token please HELP
    By Creeper in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 1st, 2012, 03:12 PM
  2. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  3. Why the error said "few parameters expected 7" while i only have 6 fields?
    By Hafiz Mughni in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 9th, 2011, 10:45 AM
  4. Syntax error on token ";", @ expected after this token
    By MagicMojo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 16th, 2011, 07:48 AM
  5. Error of "class or interface expected" at Mylong class for problem of API's
    By lostgoat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 22nd, 2009, 08:28 PM