Friday 1 March 2013

Class Object Comments in a Program


Class: A class is a non-primitive datatype that contains member variables (data) and member functions (methods) that operates on the variables.  A class is declared by the use of the class keyword.  The general form of class definition is as follows.
            Syntax:            class class-name
                                    {
                                                datatype instance-variable1;
                                                datatype instance-variable2;
                                                -
                                                -
                                                datatype instance-variablen;
                                                datatype methodname1(parameter-list)
                                                {
                                                // method body
                                                }
                                                -
                                                -
                                                datatype methodnamem(parameter-list)
                                                {
                                                // method body
                                                }
                                    }

            The data, or variables defined with in a class are called instance variables.  The code is present with in methods.  Collection of methods and variables defined with in a class are called members of the class.

            Example:         class box
                                    {
                                    double width, height, depth;
                                    double volume( )
                                    {
                                    return width*height*depth;
                                    }
                                    }

Object: Object is an instance of the class.  By means of the object only, we can access the functions (methods).
                                    main( )
                                    {
                                    box a = new box( );
                                    a.volume();
                                    }
Comments in a Program: Three types of comment statements are available in Java.  They are
i)                    Single line comment (//)
ii)                  Multi line comment (/* and */)
iii)                Documentation comment (/** and */)

1. Single line comment: For a single line comment we use double slash (//) to begin a comment.  It ends at the end of line.
            Example:         // Program for stack operations
2. Multi line comment: For more than one line of information, we use multi line comments.  Multi line comments are starts with /* and ends with */.
            Example:         /* Program for stack operations
                                        Designed by Dev
                                        Developer */
3. Documentation comment: For the documentation purpose, we use documentation comments.  Documentation comments are starts with /** and ends with */.
            Example:         /** A test for JDK
                                                @ Author S.Satya
                                                @ version 1.0 */

No comments:

Post a Comment