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 3 of 3

Thread: Method issues

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    31
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Method issues

    I have this method inside a class that extends an abstract class. This is a two part problem.

    PART 1: my toString method is loaded with errors below. I have imported java.util.* already. I've obviously missed one thing that is causing the whole method to give me an error. This same class is copied from an abstract class I created. Should my abstract contain less info and could that be causing the error?

    LongDistanceCall.java:45: class, interface, or enum expected
    public String toString() {
    ^
    LongDistanceCall.java:49: class, interface, or enum expected
    String startTimeOutput = startTime.toString(startTime); //send PreciseTime objects to 'toString()'
    ^
    LongDistanceCall.java:50: class, interface, or enum expected
    String endTimeOutput = endTime.toString(endTime);
    ^
    LongDistanceCall.java:52: class, interface, or enum expected
    costOutput += this.computeCost();
    ^

    PART 2: My class extend and abstract class. I cant determine what I'm supposed to put in my abstract class to help define my class constructor. Here's my class constructor. Should it just be blank, since I have to classes that implement the abstract?

    public class MyConstuctor extends AnAbstractClass {

    protected object o;
    protected object o2;

    public myConstructor(Object o, Object o2 ) {

    this.o = o;
    this.o2 = o2;

    } //end constructor
    }

    Thanks in advance for your help.


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Method issues

    You are most likely having a bracket problem: Something like
    public class Test
    {
        public static void main(String[] args)
        {
            if(someVariable == someOtherVariable)
            {
                if(yetAnotherVariable==someOtherOtherVariable)
                {
                    //Do stuff
                }
              }
            } //Too many brackets!
          }
        public String toString() //Will throw an error
        {
            return "String";
        }
    }
    Scan your code and check the brackets on everything. label it.

  3. #3
    Member
    Join Date
    Jul 2011
    Posts
    31
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Method issues

    Problem solved. I had an extra brace in there.

Similar Threads

  1. Recursion issues.
    By ender16 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 30th, 2011, 09:03 PM
  2. issues with Class
    By _lithium_ in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 20th, 2010, 12:49 PM
  3. Triangle issues
    By FrEaK in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 24th, 2010, 07:49 AM
  4. Replies: 0
    Last Post: October 2nd, 2009, 10:51 PM