What is Class in OOPS?

CLASS:

  • A class defines the properties and behavior (variables and methods) that is shared by all its objects. It is a blue print for the creation of objects.
  • Definition: Class is a way of binding the Data Members and Methods in a single unit.
  • Data Members of a class are also known as properties or attributes.
  • Methods of a class are also known as behaviors or accessories or functions.
  • In java, every program must be defined or developed with respect to class only i.e. No java program can be developed without the features of class.
  • In Object-Oriented Programming, we can have two types of methods. They are:

            (a) Member Methods  (b) Non-member Methods

  • Member Methods: A member method is one, which will come under the scope of a class.
  • Non-member Method: A non-member method is one, which will not come under the scope of a class.
  • Java does not allow non-member methods it allows only member-methods.
  • All the methods in java must be defined within the class only, i.e. Java Environment does not allow outside method definition.
  • Whenever we define a class, the data members of the class do not occupy the memory space. They occupy the memory space, when we create an object.
  • Syntax to define a User-defined Data type: Class

class<class-name>

{

            Variable / Data member declaration

            Method definition

}

e.g.:

Class Student

{

            int rNo;

            void result();

}

 

 

Explanation:

  • A keyword “class” is used for creating/developing user-defined data type.
  • <class-name> represents a valid java variable name and it is treated as the name of the class. Class name is basically used to create objects.
  • Whenever, we create a class, no memory space is occupied for the data members of the class.
  • Class contains two parts:

            (a) Variable Declaration or the Data Members

            (b) Method Definition

  • Variables-declaration represent, what type of data members, we use as a part of the class.
  • Methods definitions represent what type of methods, we use as a part of the class to perform specific operations.
  • Every class must start with opening curly bracket ({) and terminates with closing curly bracket (}).
  • Whenever more than one class are in same file then compiler will create .class file for all the classes, but interpreter will execute only a class which have main method.

1 Comment

  • My husband and i were absolutely thankful that Emmanuel could deal with his studies out of the ideas he discovered using your web site. It’s not at all simplistic to just choose to be giving away information which often some other people could have been trying to sell. We consider we now have the website owner to give thanks to because of that. Those illustrations you’ve made, the simple web site navigation, the relationships your site make it possible to engender – it is mostly astounding, and it is assisting our son in addition to the family do think this topic is enjoyable, and that is truly serious. Thank you for all the pieces!

Leave a Reply