0% found this document useful (0 votes)
9 views20 pages

Chapter 13 Notes

Uploaded by

Bk Siri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views20 pages

Chapter 13 Notes

Uploaded by

Bk Siri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Encapsulation

and
Inheritance
ENCAPSULATION -
process of binding both data and function together
into a single unit.

class contains-
1. variables (data) that contain attributes to represent
class.
2. methods (function) that perform operations.
example-
Suppose se make a program of calculator -

1. int a ;
variables
2. int b ;
1. sum( )
2. subtract( ) methods
3. multiply( )
Access specifier -
1. public
3 java access
2. private specifier
3. protected

access specifier tells us about the scope of


variable and functions
public specifier -
variables and method declared with public access
specifier can be accessed from outside class.

variables and method declared with no access


specifier can be accessed anywhere but within the
package.
private specifier -
variables and method declared with private access
specifier can be accessed only within the same class.

protected specifier -
variables and method declared with protected access
specifier can be accessed within same package only.
Within same Within same Outside Package Outside Package
class package (subclass) (global)

public

private only to derived


class

default

protected
DIFFERENT TYPE OF
VARIABLES-
1. local variable
2. argument variable
3. instance variable (non-static)
4. class variable (static)
SCOPE OF DIFFERENT VARIABLE -

1. local variable
* variable declared inside method
* these variables are accessible only to method in
which they are declared.
2. Argument variable-
* variable used as argument in method heading.
* these are accessible only to that method.

3. Instance variable (non-static) -


* variable declared in the class but outside the function
* these are called instance variable because their values
are unique to each instance of class.
* these are accessible in whole class or program.
4. Class variable -
variable declared inside class and outside function with
static modifier
it will be available as a single copy to all instance of class.

it can be accessed in whole class or program.


class area
{
static double pi = 3.14 ;
int radius ;
public int calculate( int r )
{
radius = r ;
double area = pi*(radius*radius) ;
return area ;
}
void display ( )
{
int a ;
a = calculate(5) ;
System.out.println(a);
}
}
INHERITANCE - parent class
or
base class
Process in which one class or
super class
acquires properties of
another class . it
implements the feature of
child class
reusability.
or
sub class
Types of Inheritance -
1. single inheritance - A
when a class is derived
from only one base
class . B
2. multiple inheritance -

when a child class A B


is inherited from
various parent
classes.
C
3. heirarchical inheritance -

when many sub


classes are inherited
A
from a single base
class.

B C D
4. Hybrid inheritance
A
when more than one
type of inheritance
are fused together ,
B C
its called hybrid
inheritance. D
5. Multilevel
inheritance A
when a sub class us
inherited from a class B
that itself is inherited
from some another
class. C
Need for inheritance-
1. it divides program into useful and reusable set of
codes.
2. any changes made in parent class are reflected in
sub class.
THANKS FOR WATCHING

You might also like