Classes and Objects

Java is an object oriented programming language.it resolved complex probleams into smaller sets by creating objects.
This objects provide two characteristics:

  1. State
  2. Behavior

 Bellow are few examples:

1.Door is object
  1.It can be in close or open state.
  2.You can turn close and open door (behavior).

3.Car is an object
   1. It has gear ,four wheels, 4 door etc status.
   2. It has breaking ,acceleration ,changing gears and open/close door etc. behavior.

Java Class:
Class is the core of java language.A class is a template or blueprints that is used to create objects. Class representation of object and the sets of operation that can be applied to such objects.class consists of Data members and methods.

let's take a few example:

Syntx: 
      public class {
        Data Members:
        Methods;
      }

Example:
       public class Student{
         String name
         int rollNo
       }

 Private,Protected and Public are called visibility levels 
 The members that are declared private can be accessed only from within the class.
 public members can be accessed from outside the class also.

Java Objects:


In above example Student student =new Student()://student is instance/object of the Student class.It will take memory in heap area and new operator dynamically allocates memory for this object.


when an object initialized ,it's called an instance. Each instance contains its own copy of these variable For Example: name and age are variable for object student is different.

This is a basic introduction on java Class and Objects.Check these chapters in sequence to learn more:
 Java Methods.
 Java Constructors
 Java Access Modifiers.
 Java this Keyword

 Java garbage collection.


No comments: