Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6788831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:31:54+00:00 2026-05-26T17:31:54+00:00

Lets say I am implementing a calculator which adds two numbers. Since we want

  • 0

Lets say I am implementing a calculator which adds two numbers.

Since we want to keep track of the partial result so far, we need to maintain two member variables, oldNum for the partial result, and newNum for the currently entered number.

Now at some point there will be an add method, which adds newNum to oldNum and stores the result in oldNum.

Since both newNum and oldNum are member fields, we don’t need to pass or return anything in the add method.

On the other hand, if you read the source code and you encounter a void method add without any parameters this might look strange.

So my question is whether there are sometimes situations where you want to pass a member field to a member function.

It would look something like:

class Calc {

   int oldNum, newNum;

   public void add1() {
    oldNum = oldNum + newNum;

  }
public int add2(int n1, int n2) {
        return n1 + n2;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:31:55+00:00Added an answer on May 26, 2026 at 5:31 pm

    There isn’t anything strange about returning void here, you are changing the internal state of the object. You could either return this, void, or a copy of the result of the addition if you wanted to provide an output.

    The add2(…) method you wrote doesn’t use any member variables, which should be implemented as a static method, which doesn’t require the object to be instantiated. However, I don’t think you need that here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

lets say i have a method which has two parameters. i have been implementing
Lets say I've got two interchangeable pieces of code and I want to figure
Lets say I have a single object of type Car which I want to
Mysql uses B+ tree for implementing indexes. Lets say my primary index is of
Lets say we have a program which contains such classes: public interface AbstractItem {
So im struggling with the idea of implementing MVC pattern on a (lets say)
Using ActionScript 3, suppose I have an array of numbers, lets say: 1, 2,
Lets say I have a class, which implements a generic interface public interface IItem
Lets say that I have two tables. Table 1 is a list of vendors
Lets say I have a Dictionary object: Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.