Home arrow Java arrow Page 3 - A Fast Gateway to OOP in Java using NetBeans IDE
JAVA

A Fast Gateway to OOP in Java using NetBeans IDE


This series introduces you to object oriented programming in Java visually using NetBeans IDE. This series will be a bit different from traditional introductions to OOP in Java. In traditional introductions of OOP in Java, we are generally used to working with console applications using the command line.

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 4
June 26, 2006
TABLE OF CONTENTS:
  1. · A Fast Gateway to OOP in Java using NetBeans IDE
  2. · Adding your own class
  3. · Customizing your own class
  4. · Accessing the members in “test”
  5. · Working with more than one object

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
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.”


blog comments powered by Disqus
JAVA ARTICLES

- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...
- Generics and Limitations in Java
- Getting Started with Java Web Development in...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials