0% found this document useful (0 votes)
5 views

class and object,cosntructor, block notes

Java Program

Uploaded by

sshinde1622
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

class and object,cosntructor, block notes

Java Program

Uploaded by

sshinde1622
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

OOP(Object Oriented Programming) Concept

1. class and object


2. Encapsulation
3. Abstraction
4. Inheritance
5. Polymorphism

1. class and object


OBJECT => any real world entity (it can be physical as well as logical)

There are 3 types of objects


i.tangible object => which we can see and touch e.g pen,chair
ii.intagible object => which we can see and but can't touch e.g banking
application
iii.conceptual obj => which we can't see and can't touch e.g ideas and
imagination

***object characteristics

1. state(instance variables) => data/value/property/instance


variables/attributes/fields of an obj
2. behavior(instance methods)=> represent the
behavior(functionality)/methods/instance method
=> opeartion performed by that object
3. Identity=> An obj is typically implemented via a unique id. and that id is
not visible to external user

CLASS => group of objects which have common properties. it is logical entity

A class contain

1. field/instance var => the data/var defined inside the class but outside
method is called as instance varibles/fields/data members of class
2. methods => class needs to have to operate on the data or an
instance var
3. constructor
4. block
5. nested class and interface

Syntax of Class:

class class_name(first letter uppercase letter)


{

instance varibles/class variables1;


instance varibles/class variables2;
.
.
.

instance method1;

instance method2;

.
.
.
};

* Process of creating objects


1. declare object

Student pooja = new Student();

syntax: class_name obj_name;


E.g Employee e1;

2. instantiate object or assign the object refrence to the variable we can use
new operator to dynamically allocate memory for an object

e1= new Empolyee();

**** understanding Methods/function


Syntax:
return_type method_name(parameter list)
{
//body of method
}

int mul(int a,int b) //method


{

return a+b;
}

=> Every method has 4 parts


1.return type => specifies that which type of value is going to be
returned by the method to the user

2.method name => specifies the name of method.It is an any valid java
identifier(user defined names)

3.parameter list => A method that accepts parameters must list the
parameters listin the method declaration.
The parameters are placed in a parameter list inside
the parentheses that follow the method name.
For each parameter used by the method, you list the
parameter type followed by the parameter name.

*****Initializing instance variables of objects

There 3 ways to initailize instance variable of object


1. calling method
2. calling instance var
3. calling constructor
***** Constructor
- constructor is used to initialized/store value to the object(instance var)
at the time of object creation.
- Constructor is a special type of member function

costructor characteristics
1. It performs automatic initialization of object
2. constructor name should be same as class name
3. constructor has no return type, not even void

types of cons:
i. default constructor
the constructor which does not have any arg/parameter.
- class_name( )
{
//body of cons
}

ii. parameterized constructor


the constructor which does have at least one or more arg.
- class_name(parameter_list)
{
//body of cons
}

****instance initializer block and Static block

- It is similar to the method which has no name. It can written inside the class
but not inside the method
- It is always executed before the costructor.
- we can use variables only inside instance initializer block not method
- Its compulsory to create the object of the class if you use instance
initializer block in your class

Syntax:

{
//initializes instances var/data member
}

You might also like