A Fast Gateway to OOP in Java using NetBeans IDE - Customizing your own class
(Page 3 of 5 )
Make sure that you have completed all the steps in all of the previous sections before proceeding through this section.

Once you are in the source view of “MyCalc.java,” modify your code in such a way that it looks like the following:
public class MyCalc {
int x=0;
int y=0;
/** Creates a new instance of MyCalc */
public MyCalc() {
}
public int getSum() {
int z;
z = x + y;
return z;
}
}
Let us start with some terminology first. The above code is simply a “class” named “MyCalc.” Every class must be named. Every variable or any function declared within a class can be called as a “member” of the class. According to the above code, “x”, “y” and “getSum” are members of the class “MyCalc.”
The variable “z” cannot be considered a “member” of the class because it is declared inside a function. In fact, it is considered to be “local” and “accessible” to “getSum” only (we shall learn more about this later).
Proceeding further, every function defined within a “class” is called a “method.” Similarly, every variable declared inside the class (in this case “x” and “y”) is called a “Field/Attribute.” Please be aware that a class can contain any number of “members” and the “members” could be “Fields/methods/etc.”
Next: Accessing the members in “test” >>
More Java Articles
More By Jagadish Chaterjee