0% found this document useful (0 votes)
24 views18 pages

OOP Concepts in Java: Unit 1 Overview

The document provides an introduction to Object-Oriented Programming (OOP) using Java, detailing its features, different editions, and environment setup including JDK, JRE, and JVM. It covers fundamental concepts such as the main() method, types of comments, variables, data types, operators, and decision-making structures in Java. Additionally, it highlights Java's applications in web and mobile development, its advantages, and its history as a programming language.

Uploaded by

ridoysarker96
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)
24 views18 pages

OOP Concepts in Java: Unit 1 Overview

The document provides an introduction to Object-Oriented Programming (OOP) using Java, detailing its features, different editions, and environment setup including JDK, JRE, and JVM. It covers fundamental concepts such as the main() method, types of comments, variables, data types, operators, and decision-making structures in Java. Additionally, it highlights Java's applications in web and mobile development, its advantages, and its history as a programming language.

Uploaded by

ridoysarker96
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

0bject oriented Programming using Java 1

Unit 1

OOP USING JAVA


UNIT-1

[RIDAY SARKAR]
0bject oriented Programming using Java 1
Unit 1
Introduction

Java is an object-oriented, class-based, secured, platform-independent, and


general-purpose programming language. Java was originally developed by James
Gosling at Sun Microsystems and released in 1995 as a core component of Sun
Microsystem’s Java platform. Java programming language is based on the write
once, run anywhere (WORA) principle, meaning that compiled Java code can run
on all platforms that support Java without the need for recompilation. Java
applications are typically compiled to bytecode that can run on any Java Virtual
Machine (JVM) regardless of the underlying operating system.

Different Editions of Java

There are four editions of the Java programming language.


 Standard Edition (Java SE)
 Enterprise Edition (Java EE)
 Micro Edition (Java ME)
 JavaFX

1. Java Standard Editions (JSE): It is used to create programs for a desktop


computer.
[Link] Enterprise Edition (JEE): It is used to create large programs that run on
the server and manages heavy traffic and complex transactions.
[Link] Micro Edition (JME): It is used to develop applications for small devices
such as set-top boxes, phone, and appliances.
[Link]: JavaFX is another edition of java technology, which is now merged
with Java SE 8. It is mainly used to create rich GUI (Graphical User Interface) in
java apps. It is supported by both desktop environments as well as web browsers.

Java Environment:

JDK: JDK stands for Java Development Kit. JDK provides an environment to
develop and execute the java program. JDK is a kit that includes two things -
Development Tools to provide an environment to develop your java programs
and JRE to execute your Java programs.

JRE: JRE stands for Java Runtime Environment. JRE provides an environment to
only run (not develop) the java programs onto your machine. JRE is only used by
the end-users of the system. JRE consists of libraries and other files that JVM
uses at runtime.

JVM: JVM stands for Java Virtual Machine, which is a very important part of both
JDK and JRE because it is inbuilt in both. Whatever java program you run using
0bject oriented Programming using Java 2
Unit 1
JDK and JRE goes into the JVM and JVM is responsible for executing the java
program line by line

main() Method

Before explaining the java main() method, let’s first create a simple program to
print Hello World. After that, we will explain why the main() method in java is

public static void main(String args[]).


public class HelloWorld {
public static void main(String args[]) {
[Link]("Hello World");
}
}

public: the public is an access modifier that can be used to specify who can
access this main() method. It simply defines the visibility of the method. The JVM
calls the main() method outside the class. Therefore it is necessary to make the
java main() method as public.

static: static is a keyword in java. We can make static variables and static
methods in java with the help of the static keyword. The main advantage of a
static method is that we can call this method without creating an instance of the
class. JVM calls the main() method without creating an instance of the class,
therefore it is necessary to make the java main() method static.

void: void is a return type of method. The java main() method doesn’t return any
value. Therefore, it is necessary to have a void return type.

main: main is the name of the method. It is a method where program execution
starts.

String args[]: String in java is a class that is used to work on Strings and args is a
reference variable that refers to an array of type String. If you want to pass the
argument through the command line then it is necessary to make the argument
of the main() method as String args[].

Comments are statements that are not executed by the compiler. Comments
make the program more human-readable by including the details of the code
involved. The proper use of comments makes maintenance and debugging of the
code easier.

Types of Comments

There are three types of comments in java


0bject oriented Programming using Java 3
Unit 1
 Single line comments
 Multi-line comments
 Documentation comments

 Single line comment: The single line comment is used to comment only
one line. A beginner-level programmer uses mostly single-line comments for
describing the code functionality.

Syntax:

// write your comment here

 Multi-line comments: The multi-line comments are used to comment


multiple lines of code.

Syntax:

/*
This is Multiline comment
*/

 Documentation Comments: This type of comment is used generally when


we write the code for projects. It helps to generate a documentation page for
reference, which can be used for getting information about methods present,
their parameters, etc.

Syntax:

/**Comment start
*
*tags are used in order to specify a parameter
*or method or heading.
*HTML tags can also be used
*such as <h1>
*
*comment ends*/

Variables in Java
Java variable is a name given to a memory location. It is the basic unit of storage
in a program.

 The value stored in a variable can be changed during program executi on.
 Variables in Java are only a name given to a memory location. All the
operations done on the variable affect that memory location.
 In Java, all variables must be declared before use.
0bject oriented Programming using Java 4
Unit 1

datatype: Type of data that can be stored in this variable.
data_name: Name was given to the variable.
In this way, a name can only be given to a memory location. It can be assigned
values in two ways:

 Variable Initialization
 Assigning value by taking input

How to Initialize Variables in Java?


It can be perceived with the help of 3 components that are as follows:

 datatype: Type of data that can be stored in this variable.


 variable_name: Name given to the variable.
 value: It is the initial value stored in the variable.

Types of Variables in Java


Now let us discuss different types of variables which are listed as follows:
1. Local Variables
2. Instance Variables
3. Static Variables
Data types in Java:

The data type defines the type of value that can be stored in a variable. For
example, if a variable has an int data type, it can only store an integer value. In
java, there are two categories of data types.

Primitive Data Type: A primitive data type is predefined by the language and is
named by a keyword or reserved keyword. There are eight types of primitive
data types in java such as boolean, char, int, short, byte, long, float, and double.

boolean: boolean data type specifies only one bit of information and it is used to
store only two possible values either true or false.

byte: byte data type is 8 bit signed two’s complement integer. Its value lies
between -128 to 127. It has a minimum value of -128 and a maximum value of
127 (inclusive). The byte data type is most commonly used to save memory in
large arrays.

short: short data type is a 16-bit signed two’s complement integer. It can hold
any number between -32768 to 32767 (inclusive). Like byte data type, it is
commonly used to save memory in large arrays.

int: int data type is 32-bit signed two’s complement integer. It can hold the
number between -2,147,483,648 to 2,147,483,648. The default value of the int
data type is 0.
0bject oriented Programming using Java 5
Unit 1
long: long data type is 64-bit two’s complement integer. It can hold the number
between -2^63 to 2^63-1. The default value of long data type is 0.

float: float data type is used to store floating-point numbers. The float data type
is a single-precision 32-bit IEEE 754 floating-point. It can hold 6 to 7 decimal
digits. It is recommended to use float instead of double if you need to save
memory in large arrays of floating-point numbers. The default value of float is
0.0f.

double: double data type is generally used to store decimal values. The double
data type is a double-precision 64-bit IEEE 754 floating-point. For decimal values,
this data type is generally the default choice. The default value of double is 0.0d.

char: The char data type is used to store characters. The char data type is a
single 16-bit Unicode character.

2. Non-Primitive Data Type: Non-Primitive data type refers to the objects.


ArrayList and String are some of the examples of Non-Primitive data type. We
will discuss the Non-Primitive data type later.

Types of Operators in Java


There are multiple types of operators in Java all are mentioned below:

[Link] Operators
[Link] Operators
[Link] Operator
[Link] Operators
[Link] Operators
[Link] Operator
[Link] Operators
[Link] Operators
[Link] of operator

Decision Making in Java (if, if-else, switch, break, continue, jump)


Java’s Selection statements:

 if
 if-else
 nested-if
 if-else-if
 switch-case
 jump – break, continue, return

1. if: if statement is the most simple decision-making statement. It is used to


decide whether a certain statement or block of statements will be executed or
0bject oriented Programming using Java 6
Unit 1
not i.e if a certain condition is true then a block of statements is executed
otherwise not.

Syntax:

if(condition)
{
// Statements to execute if
// condition is true
}

2. if-else: The if statement alone tells us that if a condition is true it will execute
a block of statements and if the condition is false it won’t. But what if we want
to do something else if the condition is false? Here comes the else statement.
We can use the else statement with the if statement to execute a block of code
when the condition is false.

Syntax:

if (condition)
{
// Executes this block if
// condition is true
}
else
{
// Executes this block if
// condition is false
}

3. nested-if: A nested if is an if statement that is the target of another if or else.


Nested if statements mean an if statement inside an if statement. Yes, java
allows us to nest if statements within if statements. i.e, we can place an if
statement inside another if statement.

Syntax:

if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
}
0bject oriented Programming using Java 7
Unit 1
4. if-else-if ladder: Here, a user can decide among multiple [Link] if
statements are executed from the top down. As soon as one of the conditions
controlling the if is true, the statement associated with that ‘if’ is executed, and
the rest of the ladder is bypassed. If none of the conditions is true, then the final
else statement will be executed. There can be as many as ‘else if’ blocks
associated with one ‘if’ block but only one ‘else’ block is allowed with one ‘if’
block.

if (condition)
statement;
else if (condition)
statement;
.
.
else
statement;

5. switch-case: The switch statement is a multiway branch statement. It


provides an easy way to dispatch execution to different parts of code based on
the value of the expression.

Syntax:

switch (expression)
{
case value1:
statement1;
break;
case value2:
statement2;
break;
.
.
case valueN:
statementN;
break;
default:
statementDefault;
}

while loop: A while loop is a control flow statement that allows code to be
executed repeatedly based on a given Boolean condition. The while loop can be
thought of as a repeating if statement.

for loop: for loop provides a concise way of writing the loop structure. Unlike
a while loop, a for statement consumes the initialization, condition and
0bject oriented Programming using Java 8
Unit 1
increment/decrement in one line thereby providing a shorter, easy to debug
structure of looping.

do while: do while loop is similar to while loop with only difference that it
checks for condition after executing the statements, and therefore is an example
of Exit Control Loop.
Syntax:

History of Java:

Java is an Object-Oriented programming language developed by James Gosling


in the early 1990s. The team initiated this project to develop a language for
digital devices such as set-top boxes, television, etc. Originally C++ was
considered to be used in the project but the idea was rejected for several
reasons(For instance C++ required more memory). Gosling endeavoured to a lter
and expand C++ however before long surrendered that for making another stage
called Green. James Gosling and his team called their project “Greentalk” and its
file extension was .gt and later became to known as “OAK”.

Java and the internet:


Java is a programming language that is used to create a variety of applications,
including web applications, mobile apps, and desktop software. It is also used to
create applets, which are small programs that can run within a web browser.
Java is a popular choice for internet programming because it is platform-
independent, meaning that Java programs can run on any device that has a Java
Virtual Machine (JVM). This makes Java ideal for developing applications that
need to be accessible to a wide range of users.
Java is also a secure language, which is important for internet programming. Java
applets are sandboxed, meaning that they cannot access files or resources on
the user's computer without permission. This helps to protect users from
malicious code.
Finally, Java is a powerful language that can be used to create complex
applications. Java has a large library of classes and APIs that make it easy to
develop a wide range of applications.

Here are some specific examples of how Java is used on the internet:

Web applications:
Java is a popular choice for developing web applications, including e -commerce
sites, social media platforms, and enterprise-level systems. Java frameworks
such as Spring, Struts, and Hibernate are popular choices for building web
applications.
Mobile apps:
Java can also be used to develop mobile apps for Android and iOS devices. Java
frameworks such as Android Studio and Eclipse make it easy to develop mobile
apps.
Desktop software:
0bject oriented Programming using Java 9
Unit 1
Java can also be used to develop desktop software for Windows, Mac, and Linux.
Java frameworks such as Swing and JavaFX make it easy to develop desktop
software.
Applets:
Java applets are small programs that can run within a web browser. Java applets
are often used to add interactivity to web pages.

Advantages of java:

Here are some of the advantages of Java:

Platform independent: Java is a platform-independent programming language.


This means that Java code can run on any platform that has a Java Virtual
Machine (JVM). The JVM is a software program that interprets and executes Java
bytecode.
Secure: Java is a secure programming language. Java has a number of security
features that make it difficult for malicious code to run on a Java platform. These
features include bytecode verification, sandboxing, and security managers.
Robust: Java is a robust programming language. Java has a number of features
that make it difficult for Java programs to crash. These features include strong
memory management, exception handling, and garbage collection.

Multithreaded: Java supports multithreading. This means that Java programs


can run multiple tasks at the same time. Multithreading can improve the
performance of Java programs and make them more responsive to user input.
Object-oriented: Java is an object-oriented programming language. Object-
oriented programming is a programming paradigm that emphasizes the use of
objects. Objects are data structures that contain both data and code. Object -
oriented programming can make Java programs more modular, reusable, and
maintainable.
High performance: Java is a high-performance programming language. Java
programs can run as fast as native C++ programs.
Large community:Java has a large community of developers. This means that
there are many resources available to Java developers, such as libraries,
documentation, and support forums.
These are just a few of the advantages of Java. Java is a powerful and versatile
programming language that can be used to develop a wide variety of
applications.

Java virtual machine and Byte Code:


What is JVM?

It basically refers to a set of various instructions that a machine can read and
understand directly. The CPU (Central Processing Unit) can directly process the
available machine code. The machine code is present in a binary format of 0s
and 1s. Thus, it is completely different from the source code as well as the byte
code.
0bject oriented Programming using Java 10
Unit 1

Machine code acts as the lowest-level representation of any source code for a
machine. We get this code after interpretation or compilation. It is also known
as the machine language since machines can directly read them. We need to
convert the source code generated by any language into the machine code to
make them machine-understandable. But then it becomes non-understandable
by humans (since it is present in a binary language).

What is Byte Code?

A byte code acts as an intermediate code present between a machine code and a
source code. A byte code is basically a low-level code that results from the
compilation of source code that might be present in a high-level language. A
virtual machine such as a JVM (Java Virtual Machine) processes a byte code.

Machines cannot understand a byte code. It is a non-runnable type of code that


becomes machine-understandable after an interpreter translates it into a
machine code. One needs to compile it to run on a JVM. Thus, any system that
already has JVM can easily run such a code irrespective of the OS (operating
system). The Java platform is, thus, independent.A byte code is also sometimes
known as a portable code.
Structure of Java Program:
Let's see which elements are included in the structure of a Java program. A
typical structure of a Java program contains the following elements:

 Documentation Section
 Package Declaration
 Import Statements
 Interface Section
 Class Definition
 Class Variables and Variables
 Main Method Class
 Methods and Behaviors

Documentation Section

The documentation section is an important section but optional for a Java program.
It includes basic information about a Java program. The information includes
the author's name, date of creation, version, program name, company
name, and description of the program. It improves the readability of the program.
Whatever we write in the documentation section, the Java compiler ignores the
statements during the execution of the program. To write the statements in the
documentation section, we use comments. The comments may be single-line,
multi-line, and documentation comments.
0bject oriented Programming using Java 11
Unit 1
o Single-line Comment: It starts with a pair of forwarding slash (//). For
example:
o //First Java Program

o Multi-line Comment: It starts with a /* and ends with */. We write between
these two symbols. For example:
o /*It is an example of
o multiline comment*/

o Documentation Comment: It starts with the delimiter (/**) and ends with */.
For example:
o /**It is an example of documentation comment*/

Package Declaration:
The package declaration is optional. It is placed just after the documentation
section. In this section, we declare the package name in which the class is placed.
Note that there can be only one package statement in a Java program. It must be
defined before any class and interface declaration. It is necessary because a Java
class can be placed in different packages and directories based on the module
they are used. For all these classes package belongs to a single parent directory.
We use the keyword package to declare the package name.

Import Statements:
The package contains the many predefined classes and interfaces. If we want to
use any class of a particular package, we need to import that class. The import
statement represents the class stored in the other package. We use the import
keyword to import the class. It is written before the class declaration and after
the package statement. We use the import statement in two ways, either import
a specific class or import all classes of a particular package. In a Java program,
we can use multiple import statements

Interface Section:
It is an optional section. We can create an interface in this section if required.
We use the interface keyword to create an interface. An interface is a slightly
different from the class. It contains only constants and method declarations.
Another difference is that it cannot be instantiated. We can use interface in
classes by using the implements keyword. An interface can also be used with
other interfaces by using the extends keyword. For example:

interface car
{
void start();
void stop();
}

Class Definition:
0bject oriented Programming using Java 12
Unit 1
In this section, we define the class. It is vital part of a Java program. Without the
class, we cannot create any Java program. A Java program may conation more
than one class definition. We use the class keyword to define the class. The class
is a blueprint of a Java program. It contains information about user-defined
methods, variables, and constants. Every Java program has at least one class that
contains the main() method. For example:

class Student //class definition


{
}

Class Variables and Constants:


In this section, we define variables and constants that are to be used later in the
program. In a Java program, the variables and constants are defined just after
the class definition. The variables and constants store values of the parameters.
It is used during the execution of the program. We can also decide and define
the scope of variables by using the modifiers. It defines the life of the variables.
For example:

class Student //class definition


{
String sname; //variable
int id;
double percentage;
}

Main Method Class


In this section, we define the main() method. It is essential for all Java programs.
Because the execution of all Java programs starts from the main() method. In
other words, it is an entry point of the class. It must be inside the class. Inside
the main method, we create objects and call the methods. We use the following
statement to define the main() method:

public static void main(String args[])


{
}
public class Student //class definition
{
public static void main(String args[])
{
//statements
}
}

Methods and behavior:


0bject oriented Programming using Java 13
Unit 1
In this section, we define the functionality of the program by using the methods.
The methods are the set of instructions that we want to perform. These
instructions execute at runtime and perform the specified task. For example:

public class Demo //class definition


{
public static void main(String args[])
{
void display()
{
[Link]("Welcome to javatpoint");
}
//statements
}
}

Procedural Programming vs Object-Oriented Programming:

Below are some of the differences between procedural and object-oriented


programming:

Procedural Oriented Object-Oriented Programming


Programming

In procedural programming, the In object-oriented programming,


program is divided into small the program is divided into
parts called functions. small parts called objects.

Procedural programming follows Object-oriented programming


a top-down approach. follows a bottom-up approach.

Object-oriented programming has


There is no access specifier in
access specifiers like private,
procedural programming.
public, protected, etc.

Adding new data and functions is Adding new data and function is
not easy. easy.
0bject oriented Programming using Java 14
Unit 1

Procedural Oriented Object-Oriented Programming


Programming

Procedural programming does not Object-oriented programming


have any proper way of hiding provides data hiding so it
data so it is less secure. is more secure.

In procedural programming, Overloading is possible in


overloading is not possible. object-oriented programming.

In procedural programming, there In object-oriented programming,


is no concept of data hiding and the concept of data hiding and
inheritance. inheritance is used.

In procedural programming, the In object-oriented programming,


function is more important than data is more important than
the data. function.

Procedural programming is based Object-oriented programming is


on the unreal world. based on the real world.

Procedural programming is used Object-oriented programming is


for designing medium-sized used for designing large and
programs. complex programs.

Object Oriented Programming (OOPs) Concept in Java

Abstraction:
Abstraction in Java is the process in which we only show essential
details/functionality to the user. The non-essential implementation details are
not displayed to the user.

Data Abstraction may also be defined as the process of identifying only the
required characteristics of an object ignoring the irrelevant details. The
properties and behaviours of an object differentiate it from other objects of
similar type and also help in classifying/grouping the objects.

Encapsulation:
Encapsulation is defined as the wrapping up of data under a single unit. It is the
mechanism that binds together code and the data it manipulates. Another way
to think about encapsulation is, that it is a protective shield that prevents the
data from being accessed by the code outside this shield.
0bject oriented Programming using Java 15
Unit 1
 Technically in encapsulation, the variables or data of a class is hidden from
any other class and can be accessed only through any member function of its
own class in which it is declared.
 As in encapsulation, the data in a class is hidden from other classes using the
data hiding concept which is achieved by making the members or methods
of a class private, and the class is exposed to the end-user or the world
without providing any details behind implementation using the abstraction
concept, so it is also known as a combination of data-hiding and abstraction.
 Encapsulation can be achieved by Declaring all the variables in the class as
private and writing public methods in the class to set and get the values of
variables.
 It is more defined with the setter and getter method.

Advantages of Encapsulation

Data Hiding: it is a way of restricting the access of our data members by hiding
the implementation details. Encapsulation also provides a way for data hiding.
The user will have no idea about the inner implementation of the class. It will
not be visible to the user how the class is storing values in the variables. The
user will only know that we are passing the values to a setter method and
variables are getting initialized with that value.
Increased Flexibility: We can make the variables of the class read-only or write-
only depending on our requirements. If we wish to make the variables read-only
then we have to omit the setter methods like setName(), setAge(), etc. from the
above program or if we wish to make the variables write-only then we have to
omit the get methods like getName(), getAge(), etc. from the above program
Reusability: Encapsulation also improves the re-usability and is easy to change
with new requirements.
Testing code is easy: Encapsulated code is easy to test for unit testing.
Freedom to programmer in implementing the details of the system: This is one
of the major advantage of encapsulation that it gives the programmer freedom
in implementing the details of a system. The only constraint on the programmer
is to maintain the abstract interface that outsiders see.

Inheritance
Java, Inheritance is an important pillar of OOP(Object-Oriented Programming). It
is the mechanism in Java by which one class is allowed to inherit the
features(fields and methods) of another class. In Java, Inheritance means
creating new classes based on existing ones. A class that inherits from another
class can reuse the methods and fields of that class. In addition, you can add
new fields and methods to your current class as well.

Why Do We Need Java Inheritance?


Code Reusability: The code written in the Superclass is common to all subclasses.
Child classes can directly use the parent class code.
Method Overriding: Method Overriding is achievable only through Inheritance.
It is one of the ways by which Java achieves Run Time Polymorphism.
0bject oriented Programming using Java 16
Unit 1
Abstraction: The concept of abstract where we do not have to provide all details
is achieved through inheritance. Abstraction only shows the functionality to the
user.

Important Terminologies Used in Java Inheritance

Class: Class is a set of objects which shares common characteristics/ behavior


and common properties/ attributes. Class is not a real-world entity. It is just a
template or blueprint or prototype from which objects are created.
Super Class/Parent Class: The class whose features are inherited is known as a
superclass(or a base class or a parent class).
Sub Class/Child Class: The class that inherits the other class is known as a
subclass(or a derived class, extended class, or child class). The subclass can add
its own fields and methods in addition to the superclass fields and methods.
Reusability: Inheritance supports the concept of “reusability”, i.e. when we want
to create a new class and there is already a class that includes some of the code
that we want, we can derive our new class from the existing class. By doing this,
we are reusing the fields and methods of the existing class.

How to Use Inheritance in Java?


The extends keyword is used for inheritance in Java. Using the extends keyword
indicates you are derived from an existing class. In other words, “extends” refers
to increased functionality.

Syntax :
class derived-class extends base-class
{
//methods and fields
}
What is Polymorphism in Java?
Polymorphism is considered one of the important features of Object-Oriented
Programming. Polymorphism allows us to perform a single action in different
ways. In other words, polymorphism allows you to define one interface and have
multiple implementations. The word “poly” means many and “morphs” means
forms, So it means many forms.

Types of Java Polymorphism


In Java Polymorphism is mainly divided into two types:
 Compile-time Polymorphism
 Runtime Polymorphism

Compile-Time Polymorphism in Java


It is also known as static polymorphism. This type of polymorphism is achieved by
function overloading or operator overloading.
Note: But Java doesn’t support the Operator Overloading.
0bject oriented Programming using Java 17
Unit 1

Method Overloading

When there are multiple functions with the same name but different parameters
then these functions are said to be overloaded. Functions can be overloaded by
changes in the number of arguments or/and a change in the type of arguments.

Subtypes of Compile-time Polymorphism


1. Function Overloading
It is a feature in C++ where multiple functions can have the same name but with
different parameter lists. The compiler will decide which function to call based
on the number and types of arguments passed to the function.
2. Operator Overloading
It is a feature in C++ where the operators such as +, -, *, etc. can be given
additional meanings when applied to user-defined data types.
Runtime Polymorphism in Java
It is also known as Dynamic Method Dispatch. It is a process in which a function
call to the overridden method is resolved at Runtime. This type of polymorphis m
is achieved by Method Overriding. Method overriding, on the other hand, occurs
when a derived class has a definition for one of the member functions of the
base class. That base function is said to be

Message Passing: Objects communicate with one another by sending and


receiving information to each other. A message for an object is a request for
execution of a procedure and therefore will invoke a function in the receiving
object that generates the desired results. Message passing involves specifying
the name of the object, the name of the function and the information to be sent.

You might also like