Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Class 
 

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.

 

Class

                         

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.

Let us consider an example of a car. Manufacturer made so many cars, all cars have their own unique state but they have same behavior (you can learn about state and behavior in the topic object.). To built a car, a blueprint is required that specifies a perfect design and illustrates the vital things to manufacture a car. This blueprint or the model can now be used to manufacture thousands and  thousands of cars ready to run on the roads.

The same concept is employed in the object oriented techniques to create the objects through programming. The blueprints used to create the objects are called classes. A class defines the properties of the objects and the methods used to control an object's behavior. In terms of object-oriented programming, a class is like a template from which an instance of that class is created at run time.

After defining a class, it can be used to create objects by instantiating the class. Each object occupies some memory to hold its instance variables (i.e. its state).  The state of each object is separate from that of the others.  After an object is created, it can be used to get the desired functionality together with its class.

Now we will learn, how to define a class having methods, objects and declaration of method by a given example.

In the given example we
create a main class "Classtest" and also create a class "Example" which is outside of the main class and define a method "display" in it. Now create a class object "myExample" of class "Example" and call display() method in main class. The class "Example" is the blue print of the class "Classtest".

Here is the Code of the Example :

Classtest.java

import java.lang.*;

public class Classtest{
  public static void mainString args[] )
    {
    Example myExample = new Example();
    myExample.display();
    }
  }
  class Example
    {
      public void display(){
        System.out.println"\nIt's a example of class" );
        }
    }

Here is the Output of the Example :

C:\roseindia>javac Classtest.java

C:\roseindia>java Classtest

It's a example of class

Download This Example :

                         

» View all related tutorials
Related Tags: c class io nested definition source while ini member e il it not init art ce in no part as

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.