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

Thread: Exam problem

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Exam problem

    So the original problem stated this:

    Consider the following code, which is a portion of SomeClass. The instance variable is initialized by the constructor. The method is supposed to multiply the value passed as a parameter by the instance variable and update the value of the instance variable. However, there is a problem. Re-write this code, without renaming any variable names, to resolve the problem.

    private int number;

    public void multiplyNumbers(int number)
    {
    number = number * number;
    System.out.println("The local variable is: " + number);
    System.out.println("The instance variable is: " + number);
    }

    I was confused on what it was asking so would this work:

    private int number;

    public void multiplyNumbers(int number)
    {
    this.number = this.number * number;
    System.out.println("The local variable is: " + this.number);
    System.out.println("The instance variable is: " + number);
    }

    I just put this. in front of the variables.

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Exam problem

    What is the problem?
    Whatever you are, be a good one

Similar Threads

  1. Java question in exam help
    By jag157 in forum Object Oriented Programming
    Replies: 8
    Last Post: July 14th, 2014, 01:49 PM
  2. an exam question
    By a939 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 16th, 2014, 12:10 PM
  3. exam question help please
    By mrjavajava in forum Java Theory & Questions
    Replies: 1
    Last Post: February 3rd, 2013, 07:59 AM
  4. cant do it...i have exam tommorow...plezz help me...
    By aicue in forum Java Theory & Questions
    Replies: 3
    Last Post: January 4th, 2013, 11:49 PM
  5. cant do it...i have exam tommorow...plezz help me...
    By aicue in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 4th, 2013, 01:27 PM