[go: up one dir, main page]

0% found this document useful (0 votes)
5 views32 pages

JAVA UNIT-I-part-2

Java notes unit wise

Uploaded by

Shivasainath .k
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)
5 views32 pages

JAVA UNIT-I-part-2

Java notes unit wise

Uploaded by

Shivasainath .k
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
You are on page 1/ 32

R 20 OOPS THROUGH JAVA

INHERITANCE
INHERITANCE CONCEPT:
Inheritance in Java is a mechanism in which one object acquires all the
properties and behaviors of a parent object. It is an important part of OOPs
(Object Oriented programming system).

The idea behind inheritance in Java is that you can create new classes that
are built upon existing classes. When you inherit from an existing class, you
can reuse methods and fields of the parent class. Moreover, you can add
new methods and fields in your current class also.

Inheritance represents the IS-A relationship which is also known as a parent-


child relationship.

Advantages:
o For Method Overriding (so runtime polymorphism can be
achieved).
o For Code Reusability.
o

INHERITANCE BASICS:
Terms in Inheritance:
Class: A class is a group of objects which have common properties. It is a
template or blueprint from which objects are created.
Sub Class/Child Class: Subclass is a class which inherits the other class.
It is also called a derived class, extended class, or child class.
Super Class/Parent Class: Superclass is the class from where a subclass
inherits the features. It is also called a base class or a parent class.
Reusability: As the name specifies, reusability is a mechanism which
facilitates you to reuse the fields and methods of the existing class when you
create a new class. You can use the same fields and methods already defined
in the previous class.

Syntax:

Class Subclass extends Superclass


{
// Variables and Methods
}

[45] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
The extends keyword indicates that you are making a new class that
derives from an existing class. The meaning of "extends" is to increase
the functionality.

In the terminology of Java, a class which is inherited is called a parent or


superclass, and the new class is called child or subclass.

As displayed in the above figure, Programmer is the subclass and


Employee is the superclass. The relationship between the two classes is
Programmer IS-A Employee.
Types of Inheritance :
There are five types of inheritances, and they are as follows.

• Simple Inheritance (or) Single Inheritance


• Multiple Inheritance
• Multi-Level Inheritance
• Hierarchical Inheritance
• Hybrid Inheritance

The following picture illustrates how various inheritances are implemented:

[46] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA

INTRODUCING ACCESS CONTROL

Encapsulation links data with the code that manipulates it.


However, encapsulation provides another important attribute: access
control.
Through encapsulation, you can control what parts of a program can
access the members of a class. By controlling access, you can prevent
misuse.

Java‟s access specifiers are: Public, Private, Protected and Default.

[47] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA

When a member of a class is modified by the public specifier,


then that member can be accessed by any other code.
When a member of a class is specified as private, then that
member can only be accessed by other members of its class.
When no access specifier is used, then by default the member of
a class is public within its own package, but cannot be accessed
outside of its package. In the classes developed so far, all
members of a class have used the default access mode, which
is essentially public.

Here is an example:

class Test {
int a; // default
access public int
b; // public access
private int c; //
private access //
methods to access
c
void setc(int i) { //
set c's value c = i;
}
int getc() { // get
c's value return
c;

[48] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
}
}
class AccessTest {
public static void
main(String args[]) { Test
ob = new Test();
// These are OK, a and b may be
accessed directly ob.a = 10;
ob.b = 20;
// This is not OK and will
cause an error // ob.c = 100;
// Error!
// You must access c through
its methods ob.setc(100); //
OK
System.out.println("a, b, and c: " +
ob.a + " " + ob.b + " " +
ob.getc());
}
}

CONSTRUCTORS
A constructor initializes an object immediately upon creation.
It has the same name as the class in which it resides and is
syntactically similar to a method.
Once defined, the constructor is automatically called
immediately after the object is created, before the new operator
completes.
Constructors have no return type, not even void. This is
because the implicit return type of a class‟ constructor is the
class type itself.

class
Box {
double
width;
double
height
;
double
depth;

[49] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
Box() {
System.out.println("Constru
cting Box"); width = 10;
height = 10; depth = 10;}

double volume() {
return width *
height * depth; }
}

class BoxDemo {
public static void
main(String args[])
{ Box mybox1 = new
Box();
Box mybox2 =
new Box();
double vol;

vol = mybox1.volume();
System.out.println("Volume
is " + vol);

vol = mybox2.volume();
System.out.println("Volume
is " + vol); }
}

Parameterized Constructors

The constructors that take parameters are called parameterized constructors.

class
Box {
double
width;
double
height
;
double
depth;
}

[50] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
Box(double w, double h,
double d) { width = w;
height =h ; depth = d;}
double volume() {
return width *
height * depth; }
}

class BoxDemo {
public static void
main(String args[]) { Box
mybox1 = new Box(10, 20,
15); Box mybox2 = new
Box(3, 6, 9); double vol;
vol = mybox1.volume();
System.out.println("Volume
is " + vol);

vol = mybox2.volume();
System.out.println("Volume
is " + vol); }
}

The output from this program is


shown here: Volume is 3000.0
Volume is 162.0

JAVA CONSTRUCTORS IN INHERITANCE

In the inheritance, the constructors never get inherited to any child


class. In java, the default constructor of a parent class called
automatically by the constructor of its child class. That means
when we create an object of the child class, the parent class
constructor executed, followed by the child class constructor
executed.

Let's look at the following example java code.

[51] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
Example:
class
ParentCl
ass{ int
a;
ParentCl
ass(){
System.out.println("Inside ParentClass constructor!");
}
}
class ChildClass extends
ParentClass{
ChildClass(){
System.out.println("Inside ChildClass constructor!!");
}
}
class ChildChildClass
extends ChildClass{
ChildChildClass(){
System.out.println("Inside ChildChildClass constructor!!");
}
}
public class
ConstructorInInheritance
{ public static void
main(String[] args) {
ChildChildClass obj = new ChildChildClass();
}
}

However, if the parent class contains both default and parameterized


constructor, then only the default constructor called automatically by the
child class constructor.
Let's look at the following example java code.

Example
class
ParentCla
ss{ int a;
ParentCla
ss(int a){
System.out.println("Inside ParentClass parameterized
constructor!"); this.a = a;
}
ParentClass(){
System.out.println("Inside ParentClass default constructor!");

[52] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
}
}
class ChildClass extends
ParentClass{
ChildClass(){
System.out.println("Inside ChildClass constructor!!");
}
}
public class
ConstructorInInheritance
{ public static void
main(String[] args) {
ChildClass obj = new
ChildClass();
}
}
Parameterized constructor of parent class must be called explicitly using the
super keyword.

JAVA SUPER KEYWORD


In java, super is a keyword used to refers to the parent class object. The super
keyword came into existence to solve the naming conflicts in the inheritance.
When both parent class and child class have members with the same name,
then the super keyword is used to refer to the parent class version.

In java, the super keyword is used for the following purposes:

• To refer parent class data members

• To refer parent class methods

• To call parent class constructor

🔔 The super keyword is used inside the child class only.

1. Super to refer parent class data members

[53] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
When both parent class and child class have data members with the same
name, then the super keyword is used to refer to the parent class data
member from child class.

Let's look at the following example java code.

Example

class
ParentCla
ss{ int
num = 10;
}
class ChildClass extends
ParentClass{ int num = 20;
Void showData() {
System.out.println("Inside the
ChildClass");
System.out.println("ChildClass num = " +
num); System.out.println("ParentClass
num = " + super.num);
}
}
public class
SuperKeywordExample {
public static void
main(String[] args) {
ChildClass obj = new
ChildClass();
obj.showData();
System.out.println("\nInside the non-child class");

[54] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
System.out.println("ChildClass num = " + obj.num);
//System.out.println("ParentClass num = " + super.num); //super can't be used
here
}
}
2. Super to refer parent class method
When both parent class and child class have method with the same name,
then the super keyword is used to refer to the parent class method from
child class.
Let's look at the following example java code.

Example
Class ParentClass{
Int num1 = 10;
Void ShowData()
{

System.out.println("\nInside the ParentClass showData method");


System.out.println("ChildClass num = " + num1);
}
}
class ChildClass extends
ParentClass{ int num2 =
20;
void showData() {
System.out.println("\nInside the ChildClass
showData method"); System.out.println("ChildClass
num = " + num2); super.showData();
}

[55] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
}
public class
SuperKeywordExample {
public static void
main(String[] args) {
ChildClass obj = new
ChildClass();
obj.showData();
//super.showData(); // super can't be used here
}
}

3. Super to call parent class constructor


When an object of child class is created, it automatically calls the parent class
default-constructor before it's own. But, the parameterized constructor of
parent class must be called explicitly using the super inside the child class
constructor.

Lets look at the following example java code.

Example

class
ParentCla
ss{ int
num1;
ParentCla
ss(){
System.out.println("\nInside the ParentClass default constructor");
num1 = 10;
}
ParentClass(int value){

[56] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
System.out.println("\nInside the ParentClass parameterized constructor");

num1 = value;
}
}
class ChildClass extends
ParentClass{ int num2;
ChildClas
s(){
super(100
);
System.out.println("\nInside the ChildClass constructor");
num2 = 200;
}
}
Public class SuperKeywordExample {
Public static void main (String[] args )
{
ChildClass obj = new ChildClass();
}

}
To call the parameterized constructor of the parent class, the super keyword
must be the first statement inside the child class constructor, and we must pass
the parameter values.

USING FINAL WITH INHERITANCE

The keyword final has three uses.


• First, it can be used to create the equivalent of a
named constant.

[57] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
• Using final to Prevent Overriding
• Using final to Prevent Inheritance

1.First, it can be used to create the equivalent of a


named constant.

Class A
{
Final int n=10;
}
Class B extends A
{
Void show()
{
System.out.println(n++);//Error! Can’t be modified
}
}

2.Using final to Prevent Overriding

i. To disallow a method from being overridden, specify final


as a modifier at the start of its declaration. Methods
declared as final cannot be overridden.

class A {
final void meth() {
System.out.println("T
his is a final
method."); }
}
class B extends A {

[58] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
void meth() { // ERROR!
Can't override.
System.out.println("Illegal!");
}
}

3.Using final to Prevent Inheritance

Sometimes you will want to prevent a class from being inherited.


To do this, precede the class declaration with final. Declaring a
class as final implicitly declares all of its methods as final, too.
Final class A
}
// The following class is illegal.
class B extends A { //
ERROR! Can't subclass A
// ...
}

JAVA PYLYMORPHISM
The polymorphism is the process of defining same method with
different implementation. That means creating multiple methods
with different behaviors.
In java, polymorphism implemented using method overloading and method
overriding.

Ad hoc polymorphism:
The ad hoc polymorphism is a technique used to define the same
method with different implementations and different arguments. In
a java programming language, ad hoc polymorphism carried out
with a method overloading concept.
In ad hoc polymorphism the method binding happens at the time of
compilation. Ad hoc polymorphism is also known as compile-time
polymorphism. Every function call binded with the respective
overloaded method based on the arguments.
The ad hoc polymorphism implemented within the class only.

[59] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA

import java.util.Arrays;
public class AdHocPolymorphismExample {
void sorting(int[] list) {
Arrays.parallelSort(list);
System.out.println("Integers after sort: " + Arrays.toString(list));
}
void sorting(String[] names) {
Arrays.parallelSort(names);
System.out.println("Names after sort: " + Arrays.toString(names));
}
public static void main(String[] args) {
AdHocPolymorphismExample obj = new AdHocPolymorphismExample();
int list[] = {2, 3, 1, 5, 4};
obj.sorting(list); // Calling with integer array

String[] names = {"rama", "raja", "shyam", "seeta"};


obj.sorting(names); // Calling with String array
}
}

Pure Polymorphism:
The pure polymorphism is a technique used to define the same
method with the same arguments but different implementations. In
a java programming language, pure polymorphism carried out with
a method overriding concept.
In pure polymorphism, the method binding happens at run time.
Pure polymorphism is also known as run-time polymorphism.
Every function call binding with the respective overridden method
based on the object reference.
When a child class has a definition for a member function of the
parent class, the parent class function is said to be overridden.
The pure polymorphism implemented in the
inheritance concept only.

[60] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
Let's look at the following example java code.
class ParentClass{
int num = 10;
void showData() {
System.out.println("Inside ParentClass showData() method");
System.out.println("num = " + num);
}
}
class ChildClass extends ParentClass{

void showData() {
System.out.println("Inside ChildClass showData() method");
System.out.println("num = " + num);

}
public class PurePolymorphism {
public static void main(String[] args) {
ParentClass obj = new ParentClass();
obj.showData();
obj = new ChildClass();
obj.showData();
}
}

JAVA METHOD OVERRIDING

The method overriding is the process of re-defining a method in a child class


that is already defined in the parent class. When both parent and child classes
have the same method, then that method is said to be the overriding method.

The method overriding enables the child class to change the


implementation of the method which acquired from parent class
[61] Syeda Sumaiya
Afreen
R 20 OOPS THROUGH JAVA
according to its requirement.

In the case of the method overriding, the method binding happens


at run time. The method binding which happens at run time is
known as late binding. So, the method overriding follows late
binding.

The method overriding is also known as dynamic method


dispatch or run time polymorphism or pure polymorphism.

Let's look at the following example java code.

class ParentClass{

int num = 10;

void showData() {

System.out.println("Inside ParentClass showData() method");


System.out.println("num = " + num);

class ChildClass extends ParentClass{ void showData() {

System.out.println("Inside ChildClass showData() method");


System.out.println("num = " + num);

public class PurePolymorphism {

public static void main(String[] args) { ParentClass obj = new


ParentClass();

obj.showData();

obj = new ChildClass();

[62] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
obj.showData();

10 Rules for method overriding:


While overriding a method, we must follow the below list of rules.

• Static methods can not be overridden.


• Final methods can not be overridden.
• Private methods can not be overridden.
• Constructor can not be overridden.
• An abstract method must be overridden.
• Use super keyword to invoke overridden method from child class.
• The return type of the overriding method must be same as the parent has
it.
• The access specifier of the overriding method can be changed,
but the visibility must increase but not decrease. For example,
a protected method in the parent class can be made public, but
not private, in the child class.
• If the overridden method does not throw an exception in the
parent class, then the child class overriding method can only
throw the unchecked exception, throwing a checked exception
is not allowed.
• If the parent class overridden method does throw an
exception, then the child class overriding method can only
throw the same, or subclass exception, or it may not throw any
exception.

JAVA ABSTRACT CLASS


An abstract class is a class that created using abstract keyword. In
other words, a class prefixed with abstract keyword is known as an
abstract class.
In java, an abstract class may contain abstract methods (methods
without implementation) and also non-abstract methods (methods
with implementation).
We use the following syntax to create an abstract class.

[63] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
Syntax:
abstract class <ClassName>{
}
Let's look at the following example java code:
import java.util.*;

abstract class Shape {


int length, breadth, radius;
Scanner input = new Scanner(System.in); abstract void printArea();
}

class Rectangle extends Shape { void printArea() {


System.out.println("*** Finding the Area of Rectangle ***"); System.out.print("Enter
length and breadth: ");
length = input.nextInt(); breadth = input.nextInt();
System.out.println("The area of Rectangle is: " + length *
breadth);
}
}

class Triangle extends Shape { void printArea() {


System.out.println("\n*** Finding the Area of Triangle ***"); System.out.print("Enter
Base And Height: ");
length = input.nextInt(); breadth = input.nextInt();
System.out.println("The area of Triangle is: " + (length *
breadth) / 2);
}
}
class Cricle extends Shape { void printArea() {

System.out.println("\n*** Finding the Area of Cricle ***"); System.out.print("Enter Radius:


");

radius = input.nextInt();

System.out.println("The area of Cricle is: " + 3.14f * radius *

radius);

[64] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
public class AbstractClassExample {
public static void main(String[] args) { Rectangle rec = new Rectangle();

rec.printArea();
Triangle tri = new Triangle();
tri.printArea();
Cricle cri = new Cricle();
cri.printArea();
}
}

8 Rules for method overriding:


• An abstract class must follow the below list of rules.

• An abstract class must be created with abstract keyword.


• An abstract class can be created without any abstract method.
• An abstract class may contain abstract methods and non-abstract methods.
• An abstract class may contain final methods that can not be overridden.
• An abstract class may contain static methods, but the abstract
method can not be static.
• An abstract class may have a constructor that gets executed when the
child class object created.
• An abstract method must be overridden by the child class, otherwise,
it must be defined as an abstract class.
• An abstract class can not be instantiated but can be referenced.

THE OBJECT CLASS

✓ There is one special class, Object, defined by Java.


✓ All other classes are subclasses of Object. That is, Object is
a superclass of all other classes. This means that a reference
variable of type Object can refer to an object of any other

[65] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
class.
✓ Also, since arrays are implemented as classes, a variable of
type Object can also refer to any array.
✓ Object defines the following methods, which means that
they are available in every object.

Method Purpose

Creates a new object that is the same


Object clone( )
as the object being cloned.

Determines whether one object is equal to


boolean equals(Object object)
another.

void finalize( ) Called before an unused object is recycled.

Class getClass( ) Obtains the class of an object at run time.

Returns the hash code associated with the


int hashCode( )
invoking object.

Resumes execution of a thread waiting on the


void notify( )
invoking object.

void notifyAll( ) Resumes execution of


all threads waiting on the invoking object

String toString( ) Returns a string that describes the object.

void wait( )
void wait(long milliseconds)
Waits on another thread of execution.
void wait(long milliseconds, int
nanoseconds)

[66] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA

FORMS OF INHERITANCE
Subclass, Subtype, Substitutability:

In programming languages, inheritance means:


Data and behaviour of parent class are part of child
Child class may include data and behaviour not in parent

Subclass & Subtype


To assert that one class is a subclass of another is to simply say it was
built using inheritance.
To assert that one class is a subtype of another is to say that it preserves
the purpose of the original.

The two concepts are independent:


Not all subclasses are subtypes
Sometimes subtypes are constructed without being subclasses

Substitutability:

In order to satisfy substitutability it has to satisfy following properties:


Instances of the subclass must possess all data areas associated with the
parent class.
Instances of the subclass must implement, through inheritance at least
(if not explicitly overridden) all functionality defined for the parent
class.
Thus, an instance of the child class can mimic the behaviour of the
parent class.

Note: Subtypes must satisfy the substitution principle, which means that
[67] Syeda Sumaiya
Afreen
R 20 OOPS THROUGH JAVA
any code that relies on B’s specification will function properly if A’s
implementation is substituted for B.

We have 6 Forms of Inheritance in Java:

o Specialization

o Specification

o Construction

o Generalization or Extension

o Limitation

o Combination

1. Specialization Inheritance

✓ By far the most common form of inheritance is specialization

✓ Each child class overrides a method inherited from the parent in order

to specialize the class in some way

Example:

[68] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA

class First
{
void show()
{
System.out.println(―Hello‖);
}
void showA()
{
System.out.println(―Welcome‖);
}
}

class Second extends First


{
void show()
{
System.out.println(―Hi‖);
}
void showA()
{
System.out.println(―Hello‖);
}
}

2. Specification Inheritance

If the parent class is abstract, we often say that it is providing a specification


for the child class.

[69] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
abstract class First
{
abstarct void show();
abstract void showA();
}

class Second extends First


{
void show()
{
System.out.println(―Hi‖);
}
void showA()
{
System.out.println(―Hello‖);
}
}

3. Inheritance for Construction

✓ If the parent class is used as a source for behavior, but the child class has

no is-a relationship to the parent, then we say the child class is using
inheritance for construction

✓ Generally not a good idea, since it can break the principle of

substitutability, but nevertheless sometimes found in practice (More


often in dynamically typed languages, such as Smalltalk)

class First
{
void show()
[70] Syeda Sumaiya
Afreen
R 20 OOPS THROUGH JAVA
{
System.out.println(―Hello‖);
}
void showA()
{
System.out.println(―Welcome‖);
}
}

class Second extends First


{
void set(int a, int b)
{
.........
.........
}

void add()
{
..........
........... }

4. Inheritance for Generalization or Extension

✓ If a child class generalizes or extends the parent class by providing

more

functionality, but does not override any method, we call it inheritance for
generalization

[71] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
✓ The child class doesn't change anything inherited from the parent, it

simply adds new features

class First

{
void set(int a, int b)
{
.........
.........
}

void add()
{
..........
...........
}

class Second extends First


{
void show()
{
..............
}
}

5. Inheritance for Limitation

✓ If a child class overrides a method inherited from the parent in a way that

[72] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
makes it unusable (for example, issues an error message), then we call it
inheritance for limitation

✓ Generally not a good idea, since it breaks the idea of substitution. But

again, it is sometimes found in practice

class First

{
void set(int a, int b)
{// initialization}

void add()
{
..........
...........
}

class Second extends First


{
void set()
{
//display
}
}

6. Inheritance for Combination

The child class inherits features from more than one parent class. Although
multiple inheritance is not supported directly by Java, it can be achieved using
interfaces.
[73] Syeda Sumaiya
Afreen
R 20 OOPS THROUGH JAVA

interface A
{
……
}

interface B
{
…….
}

class C implements A, B
{
……..
}

SUMMARY OF FORMS OF INHERITANCE

 Specialization

The child class is a special case of the parent class, in other words, the
child class is a subtype of the parent class.

 Specification

The parent class defines behaviour that is implemented in the child class but
not in the parent class.

 Construction

The child class makes use of the behaviour provided by the parent class, but is

[74] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
not a subtype of the parent class.

 Generalizaton

The child class modifies or overrides some of the methods of the parent
class.

 Extension

The child class adds new functionality to the parent class, but does not
change any inherited behavior.

 Limitation

The child class restricts the use of some of the behavior inherited from the
parent class.

 Combination

The child class inherits features from more than one parent class. This is
multiple inheritance.

BENEFITS OF INHERITANCE

• Inheritance helps in code reuse. The child class may use the
code defined in the parent class without re-writing it.
• Inheritance can save time and effort as the main code need not
be written again.
• Inheritance provides a clear model structure which is easy to
understand.
• An inheritance leads to less development and maintenance
costs.
• With inheritance, we will be able to override the methods of
the base class so that the meaningful implementation of the
base class method can be designed in the derived class. An

[75] Syeda Sumaiya


Afreen
R 20 OOPS THROUGH JAVA
inheritance leads to less development and maintenance costs.
• In inheritance base class can decide to keep some data private
so that it cannot be altered by the derived class.

COSTS OF INHERITANCE

• Inheritance decreases the execution speed due to the


increased time and effort it takes, the program to jump
through all the levels of overloaded classes.
• Inheritance makes the two classes (base and inherited class)
get tightly coupled. This means one cannot be used
independently of each other.
• The changes made in the parent class will affect the behavior
of child class too.
• The overuse of inheritance makes the program more
complex

[76] Syeda Sumaiya


Afreen

You might also like