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

Thread: Creating a static method that requires no arguments and returns no values.

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Location
    Virginia
    Posts
    4
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Creating a static method that requires no arguments and returns no values.

    Hello forum! I am doing an assignment and I am clueless as to what I did wrong or supposed to do in terms of placement of coding. If someone could dumb down their response and tell me what I did wrong I would greatly appreciate it.

    This is what I supposed to do:

    1.) Type the following shell for the class:

    public class ParadiseInfo
    {
    }


    2.) Between curly braces of the class, indent a few spaces and create the shell for the main() method:

    public static void main(String[] args)
    {
    }


    3.) Between the braces of the main()Method, insert a call to the displayInfo() method:

    displayInfo();

    4.) Place the displayInfo() method outside of the main() method, just before the closing curly brace for the ParadiseInfo class:

    public static void displayInfo()
    {
    system.out.println ("Paradise Day Spa wants to pamper you.");
    system.out.println ("We will make you look good.");
    }


    This is what I attempted to do:
    I know it is wrong I am just clueless on where to put the code and why



    public class ParadiseInfo
    {
    displayInfo();

    public static void main(String[] args)
    {
    public static void displayInfo();
    }

    system.out.println("Paradise Day Spa wants to pamper you.");
    system.out.println("We will make you look good.");

    }


    I appreciate any help or insight..Thanks!!

    --- Update ---

    I also tried it this one and ended up with 1 error..


    public class ParadiseInfo
    {
    displayInfo();

    public static void main(String[] args)
    {

    }
    public static void displayInfo();
    {
    system.out.println("Paradise Day Spa wants to pamper you.");
    system.out.println("We will make you look good.");
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,316
    Thanks
    53
    Thanked 2,391 Times in 2,345 Posts

    Default Re: Creating a static method that requires no arguments and returns no values.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    ended up with 1 error..
    When you get errors, copy the full text and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: Creating a static method that requires no arguments and returns no values.

    That 2nd try is a little closer, but that call to displayinfo(); is just sorta hanging out in the top of the class where the variables and method definitions go. There's no way to reach it and I think a compiler will freak out if it sees a function in a place like that. Calls to methods like that need to be inside the body of another method, such as main().

  4. #4
    Junior Member
    Join Date
    Sep 2014
    Location
    Virginia
    Posts
    4
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Creating a static method that requires no arguments and returns no values.

    I tried this again and I still don't know what I am doing wrong. Is this closer or farther away from what I already tried? lol

     
    public class ParadiseInfo
    {
    	displayInfo();
     
    	public static void main(String[] args)
    	{
     
    	}
    		public static void displayInfo();
    	{
    	system.out.println("Paradise Day Spa wants to pamper you.");
    	system.out.println("We will make you look good.");
    	}
    }

    The error that I got: G:\ParadiseInfo.java:3: error: invalid method declaration; return type required
    displayInfo();
    ^
    1 error

    Tool completed with exit code 1

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,316
    Thanks
    53
    Thanked 2,391 Times in 2,345 Posts

    Default Re: Creating a static method that requires no arguments and returns no values.

    Executable code like that method call must be coded inside of a method. See also post#3
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: Creating a static method that requires no arguments and returns no values.

    You shouldn't call a function outside the body of a function (which you did on line 3). You've also left your main function completely empty so your program won't do anything.

    Also, don't put a semicolon at the end of a function signature ( public static void displayInfo(); ). You really only do something like that if you're defining an interface.

Similar Threads

  1. Replies: 2
    Last Post: May 27th, 2014, 12:36 PM
  2. I need help on creating a method to handle minimum and maximum input values
    By Manzanita in forum Object Oriented Programming
    Replies: 1
    Last Post: April 2nd, 2014, 02:22 AM
  3. Replies: 2
    Last Post: February 18th, 2014, 05:20 PM
  4. How to call a static method within a static method in the same class?
    By EDale in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 10th, 2013, 04:13 AM
  5. Creating Method that returns a casted object type
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: October 31st, 2012, 01:23 PM