Classes and Objects

Objects and classes are the fundamental parts of object-orientated programming technique. A class can contains both data as well as methods. A simple class having no method must contain a method known as main() method. Execution of any class starts from t

Classes and Objects

Objects and classes are the fundamental parts of object-orientated programming technique. A class can contains both data as well as methods. A simple class having no method must contain a method known as main() method. Execution of any class starts from t

Classes and Objects

Classes and Objects

     

Objects and classes are the fundamental parts of object-orientated programming technique. A class can contains both data as well as methods. A simple class having no method must contain a method known as main() method. Execution of any class starts from the main() method. 

A class can have more than one instances (objects), let us consider a class employee having the employee details that serves for the employees of an organization, each time we create a new object for each employee. While all the employees share the same template (i.e. employee class). This section illustrates how to define our own classes, that includes declaring and defining of member variables, methods, and constructors. We also try to cover nesting of classes within other classes, enum and annotations.

  1. Classes:
    This section explores the concept of a class in reference to object oriented programming techniques. A class defines the properties of  objects and methods used to control an object's behavior. In terms of object-oriented programming, the class is like a template from which an instance (object) of a class is created at run time.
       
  2. Objects:
    A
    n object is the combination of related states and behavior in which variables are just like states and the methods are just like behaviors (providing some functionality). In an object, variables store values for later use and methods are the unit of codes that provides a particular functionality. We can say objects are the basic units of the object-oriented programming. 
      

  3. Nested Classes:
    One more advantage of Java, as an object-oriented programming language is that it allows us to define a class within another class, such classes are known as nested classes.
       
  4. Enum Types: 
    Enum is a keyword which was introduced in Java 5. It is a particular type of class whose instances are only those objects which are members of that enum. The super class of all enum objects is java.lang.Enum, apart from this enum can not be extended.
        
  5. Annotations:
    Annotation is one more powerful feature of Java, an object-oriented programming language included in JDK 1.5. Annotations were introduced in September 2004  and added to the Java language through specification.