java classes

Object Oriented Programming Components

What is Class ?

1. Class is a blueprint or template of an Object.
2. Class is a group of objects which have same State and Behaviour.
3. Class is a container that contain following things:

  1. Data Type
  2. Method
  3. Constructor
  4. Block

  1. Data Type

  2. In Data Type we cover all the following things:

    • Data Type in Java
    • Variable in Java
    • Type Casting in Java
    • Wrapper Class in Java
    • Modifiers in Java
  3. Method

  4. Method is set of code or instruction to perform some operation.
    It is used to represent the behaviour of an object.
    A method must be declared within a class. It is defined with the name of the method, followed by parentheses ().

    Rules for a method :

    Method must have an access modifiers like private, default, protected or public.
    Method has an optional to use non access modifiers like static, final, abstract, synchronized etc.
    Method must have a return type.
    Method must have a name or identifiers in which we call a method.
    Method name should be declare in camel case like add(), addTwoNumber() etc.

    There are two type of methods in Java :

    • Non-Parameterized Method
    • Parameterized Method
  5. Constructor

  6. Constructor is used to initialize the property.
    Constructor must be the class name.
    Constructor must have an access modifiers.
    Constructor never have any non-access modifiers.
    Constructor always call by the new keyword.
    Constructor never have any return type.
    Constructor always return same type of object.

    There are two type of Constructors :
    • Default Constructor or Non-Parameterized Constructor
    • Parameterized Constructor
  7. Blocks

  8. Blocks are self executable.
    Block has no name.
    Block is used to perform some callback before initialized any thing.
    Blocks are define inside class.

    There are two types of blocks:
    • Static Block
    • Non-Static block