CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2013
    Posts
    1

    What is _a_? and how it works?

    Code:
    public class Dimensions {
        
        private int _a_, _b_;
        
        public Dimensions(int a, int b) { 
        	setA(a); 
        	setB(b); 
        }
        
        public void setA(int a) { 
        	assert x>0; 
        	_a_ = a; 
        }
        
        public void setB(int b) { 
        	assert y>0;
        	_b_ = b; 
        }
        
        public int getA() { 
        	return _a_; 
        }
        
        public int getB() { 
        	return _b_; 
        }
    }
    Hi everyone.
    I am new in Java programming and i need to know what is _x_ and _y_, and the relationship in the setA or setB function, between the _a_ = a.

    Thanks

  2. #2
    Join Date
    Jun 2013
    Location
    New York, USA
    Posts
    21

    Re: What is _a_? and how it works?

    _a_ and _b_ are integers that can be accessed from any of your methods throughout the class. Including private (or public for that matter) in front of an int makes it accessible throughout your class. If you had public instead of private, you would be able to access that int from another class. a and b are parameter integers for that method. So basically, if there are parameters for a method, the only way to call upon that method is by including data for the required parameters which in this case is an int.

    So for example, if I were to call setA as
    setA(6); instead of setA(a);, the parameters (int a) would be set to 6. You then make it so _a_ and a are the same.

    Another way to do this would be:

    Code:
    public class Dimensions {
        
        private int a, b;
        
        public Dimensions(int a, int b) { 
        	setA(a); 
        	setB(b); 
        }
        
        public void setA(int a) { 
        	assert x>0; 
        	this.a = a; 
        }
        
        public void setB(int b) { 
        	assert y>0;
        	this.b = b; 
        }
        
        public int getA() { 
        	return a; 
        }
        
        public int getB() { 
        	return b; 
        }
    }
    From the code given I can't tell you what _x_ and _y_ are, but I would guess they are integers being passed from another class. You shouldn't use underscores like _x_ because it is improper technique and you should always start an int, double, var, char, etc with a letter.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured