header-logo.png GKINDEX

Java Class and Objects

A Java class is nothing but a template and objects is an entity of the template, Let's take an example of the student and class. Student belongs to X class, the students who are belonging to X class will have the same properties. Here Class is nothing but a template for the Students and these students belong to the same Class( Type). Still not clear lets take one more example, in this example we will consider a bricks making machine and Bricks.

The bricks making machine will make the same kind of bricks whose length and breadth will be always same. Here Bricks is nothing but an Objects and Bricks Making machine is nothing but a Class.

Class Syntax

We have many keywords in java among those "class" is one keyword. The following is the syntax for the declaring class in java.

class class_name{

}

class_name will be dynamic, we can give any name but give the name which is more relevant to the class implementation.

Creation of Objects

The Object creation Syntax will be the following.

class_name obj_name=new class_name();

Here class_name will be the name of the class, which ever we have created and obj_name will the name of the object which belongs to class_name and new is the keyword of java will be used for creation of Objects.

Student stdnt=new Student();

In the above statement, Student is a class and stdnt is the Object of the Student class. Please remember every stament in the java will be completed by the semicolon(;).

  • Share