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: Using same parameters but different functiosn? Allowed or not?

  1. #1

    Default Using same parameters but different functiosn? Allowed or not?

    I have made a class here that has two methods. As you guys can notice, in my two methods that I made, I have listed some arugments in there with parameters. My question is that the variables im using in first method, can they be identical on my second method? Is this ok to do?

    public class StudentScore
    {
    	private int math;
    	private int science;
    	private int calc;
    	private int history;
    	private int pe;
     
    	//Make a constructor
    	public StudentScore()
    	{
    		math=40;
    		science=40;
    		calc=40;
    		history=40;
    		pe=40;
     
    	}
     
    	public void getscore(int m_score,int s_score,int c_score,int h_score,int P_score)
    	{
    		math=m_score;
    		science=s_score;
    		calc=c_score;
    		history=h_score;
    		pe=P_score;
     
     
    	}
     
    	public int Scores(int m_score,int s_score,int c_score, int h_score,int P_score)


  2. #2
    Member Ganeprog's Avatar
    Join Date
    Jan 2014
    Location
    Chennai,India
    Posts
    80
    My Mood
    Love
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default Re: Using same parameters but different functiosn? Allowed or not?

    Hi,

    Of course, you can use its not a problem. But if you are using the same method name with the same arguments had a problem for that you have to study method overloading concept.

    Thanks,

  3. #3
    Member
    Join Date
    Feb 2014
    Location
    India
    Posts
    47
    My Mood
    Bored
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default Re: Using same parameters but different functiosn? Allowed or not?

    Yes. It is completely Ok. The arguments that you pass in a method have a local scope, that means they are available only till that method is alive(running) and only to that method and are finished as soon as the method is finished.

    I hope your doubt is cleared.

Similar Threads

  1. Replies: 0
    Last Post: July 16th, 2013, 11:54 PM
  2. Replies: 3
    Last Post: March 25th, 2013, 08:28 AM
  3. Replies: 2
    Last Post: May 9th, 2012, 10:32 PM
  4. Is this allowed?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 28
    Last Post: November 15th, 2010, 03:27 PM