Wednesday, June 10, 2015

Difference Between Class and Object:

7:00 AM

Difference Between Class and Object:

1.Class :  Class is a container which collection of variables and methods.

Object:::object is a instance of class

2.Class:::: No memory is allocated at the time of declaration

Object:::Sufficient memory space will be allocated for all the variables of class at the time of declaration.

3.Class:::One class definition should exist only once in the program.

Object:::::Object:For one class multiple objects can be created


Syntax of Class:

                     class Class_Name
                       { 
                                data member; 
                                 method; 
                       }  



Example of Object And Class::

   class Student
             {
                int studentid;  // data member (or instance variable)
                String studentname;  // data member (or instance variable)
                studentid=1;
                studentname="vidyarthi";
                public static void main(String args[])
                   {

                student std=new student(); // Creating an object of class Employee
                        System.out.println("Student ID: "+std.studentid);
                        System.out.println("Student Name: "+std.studentname);
                   }
              } 

              
Note: A new keyword is used to allocate memory at runtime, new keyword is used for create an object of class, later we discuss all the way for create an object of class.

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

 

© 2013 Java Tutorials. All rights resevered. Designed by Templateism

Back To Top