0


Class
A Java class is a group of values with a set of operations to manipulate this values. Classes facilitate modularity and information hiding. Classes are used to define a new data type.
class ClassName
{
            data_type variable_name;
            data_type variable_name;
           
            rerutn_type Method_name ( )
            {
                        Body of Method;
            }
            return_type Method name (parameter_list)
            {
                        Body of Method;
            }
}

Example : -

class Student
{
            int roll;
            int marks;
            void disp ( )
            {
                        system.out.println(“Roll: “ + roll );
                        system.out.println(“Marks: “ + marks);
            }
}

Object
Object is class type variable. Each time you create an object of a class a copy of each instance variables defined in the class is created. In other words you can say that each object of a class has its own copy of data members defined in the class. Member functions have only one copy and shared by all the objects of that class. All the objects may have their own value of instance variables.

New - The new operator in Java dynamically allocates memory for an object returns a reference to object and binds the reference with the object. Here reference to object means address of object. So it is essential in Java that all the objects must be dynamically allocated.
Creating Object
Class_name object_name;                  
Object_name = new class_name( ); 
Class_name object_name = new class_name( );


Example : -
Student student1;                  
Student1 = new Student( ); 
Student student1 = new Student( );

Accessing class member using object
Object_name.variable_name = value;
Student1.roll = 101;
Object_name.method_name ( )
Student1.disp ( )
Object_name.method_name (parameter_list)
Student1.total ( 45, 55)



Post a Comment

Comment Rules :
1. Do not post Adult/illegal Links.
2. Try to comment in only English Language.
3. Do not post other website's links which are useless.
4. Your Comment should be based on the Topic for other queries Kindly Visit our Contact Us Page.
5. Do not use Abusive Language.
6. Respect each other.
Thank You for following the rules. Please Comment....

 
Top