1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Very noobi question in Java

Discussion in 'Programming & Webmastering' started by Flash, Apr 20, 2011.

  1. Flash

    Joined:
    Jan 27, 2009
    Messages:
    218 (0.11/day)
    Thanks Received:
    11
    So, I'm doing some sample exercises, and I have no idea why there is a compiler error on line 6

    public class Awake {
    public void Awake(String time){
    System.out.println(“Time is “+time);
    }
    public static void main(String[] args){
    Awake a = new Awake(“up!”); //ERROR HERE
    }
    }

    Please enlighten me.
    Thanks
  2. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.29/day)
    Thanks Received:
    5,610
    Location:
    Cheeseland (Wisconsin, USA)
    What's the compiler error?
  3. Flash

    Joined:
    Jan 27, 2009
    Messages:
    218 (0.11/day)
    Thanks Received:
    11
    Cannot find symbol, constructor Awake.
  4. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.29/day)
    Thanks Received:
    5,610
    Location:
    Cheeseland (Wisconsin, USA)
    I'm not a Java expert but try removing the "void" in the constructor.

    public class Awake
    {
    public Awake(string time)
    {
    ...
    }
    }

    Make sure you have everything included to handle the System.out.println call too.
    I could be wrong. :/

    I really need to brush up on my Java.
  5. Flash

    Joined:
    Jan 27, 2009
    Messages:
    218 (0.11/day)
    Thanks Received:
    11
    Wow, don't I suck.

    Yep, void is a return type, and making it void transforms the constructor into an ordinary method.

    Thanks. Should've noticed that.
  6. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.29/day)
    Thanks Received:
    5,610
    Location:
    Cheeseland (Wisconsin, USA)
    You don't suck, Flash. Overlooking things like that happen all the time.
    I haven't programmed in Java in years and was just going by my C# experience. DOH !!
    I guess for me, even a blind squirrel finds a nut once in awhile. :laugh:
    Last edited: Apr 20, 2011
  7. 3870x2

    3870x2

    Joined:
    Feb 26, 2008
    Messages:
    4,875 (2.18/day)
    Thanks Received:
    689
    Location:
    Joplin, Mo
    Kreij makes everyone feel like they suck, he solved a problem in a language that he didn't even know :p

    Legend has it that Kreij developed the C language.

    Historians maintain that the project was stolen from him.
  8. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.29/day)
    Thanks Received:
    5,610
    Location:
    Cheeseland (Wisconsin, USA)
    Thanks for the laugh, 3870, but there are a lot of great coders here on TPU who make me look stupid in the languages I've not used in quite some time (like C++ and Java).

    We all just try to help where we can. :toast:

    BTW ... I was going to name it "K" before Dennis Ritchie stole the code and named it "C". :roll:

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page