More Related Content
Similar to Java Day-2 (20)
More from People Strategists
More from People Strategists (20)
Java Day-2
- 3. DAY 2
Object Oriented Programming
Objects And Classes
Encapsulation
Polymorphism
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
3
- 4. Introduction to Object-Oriented Programming
• The object-oriented is a programming paradigm where the program
logic and data are weaved.
• OOPs is a way of conceptualizing a program's data into discrete
"things" referred to as objects, each having its own properties and
methods.
• For example, your friend is a bank manager and he wants you to help
improving systems. The first object you might design is the
general-purpose Account. The Account object has properties and
methods. For each client your friend's bank have, you would have to
create an Account object.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
4
- 5. Introduction to Object-Oriented Programming
(Contd.)
Object
Characteristics of OOP
Class
Encapsulation
Inheritance
Polymorphism
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
5
- 6. Introduction to Object-Oriented Programming
(Contd.)
• Benefits of OOP:
• Re-usability: You can write a program using a previous developed code.
• Code Sharing: You are able to standardize the way your are programming with
your colleagues.
• Rapid Modeling: You can prototype the classes and their interaction through
a diagram.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
6
- 7. Objects
• An entity that has state and behavior is known as an object, such as chair,
bike, marker, pen, table, and car.
• It can be physical or logical (tangible and intangible).
• The example of intangible object is banking system.
• An object has three characteristics:
• State: Represents data (value) of an object.
• Behavior: Represents the behavior (functionality or action) of an object, such as
deposit and withdraw.
• Identity: Object identity is typically implemented via a unique ID. The value of the ID
is not visible to the external user.
However, it is used internally by the JVM to identify each object uniquely.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
7
- 8. Objects (Contd.)
• At any point in time, an object can be described from the data it
contains.
• An object is an instance of a class.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
8
- 9. Objects (Contd.)
• Example:
Car Objet
States:
Brand
Model
Price
Color
Behaviors:
Starting car
Stopping car
Changing gear
Applying brake
Get km/liter
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
9
- 10. Classes
• A class is a collection of objects (or values) and a corresponding set of
methods.
• Objects contain data and methods, but to use objects in a program, a class
needs to be created.
• A class lets us define what data is going to be stored in the object, how it
can be accessed and modified, and what actions can be performed on it.
• Thus, a class is a template for an object.
• Example:
A set of cars with operations, such as starting, stopping, changing gear,
applying brake, and get km/liter.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
10
- 11. Encapsulation and Access Control
• Encapsulation is the mechanism that binds together code and the
data it manipulates, and keeps both safe from outside interference
and misuse.
• A protective wrapper that prevents the code and data from being
arbitrarily accessed by other code defined outside the wrapper.
• Access to the code and data inside the wrapper is tightly controlled
through a well-defined interface.
• The basis of encapsulation is the class.
• When you create a class, you will specify the code and data that
constitute that class.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
11
- 12. Encapsulation and Access Control(Contd.)
• The data defined by the class are referred to as member variables or
instance variables.
• The code that operates on that data is referred to as member
methods.
• The complexity of the implementation inside the class can be hided.
• Each method or variable in a class may be marked private or public.
• The private methods and data can only be accessed by code that is a
member of the class.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
12
- 13. Encapsulation and Access Control(Contd.)
• The following figure describes conceptual representation of
encapsulation concept:
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
13
- 14. Inheritance
• Inheritance is the process by which one object acquires the
properties of another object.
• It supports the concept of hierarchical classification.
• For example, a Golden Retriever is part of the classification dog,
which in turn is part of the mammal class, which is under the larger
class animal.
• Without the use of hierarchies, each object would need to define all
of its characteristics explicitly.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
14
- 15. Inheritance (Contd.)
• By use of inheritance, an object need only define those qualities that
make it unique within its class. It can inherit its general attributes
from its parent.
• It is the inheritance mechanism that makes it possible for one object
to be a specific instance of a more general case.
• Inheritance interacts with encapsulation as well.
• If a given class encapsulates some attributes, then any subclass will
have the same attributes plus any that it adds as part of its
specialization.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
15
- 16. Inheritance (Contd.)
• A new subclass inherits all of the attributes of all of its ancestors.
• The following figure describes conceptual representation of
inheritance concept:
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
16
- 17. Polymorphism
• Derived from two Latin words - Poly, which means many, and
morph, which means forms.
• Polymorphism is the capability of an action or method to do different
things based on the object that it is acting upon.
• In object-oriented programming, polymorphism refers to a
programming language's ability to process objects differently
depending on their data type or class.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
17
- 18. Polymorphism, Encapsulation, and
Inheritance Work Together (Contd.)
• The following figure describes conceptual representation of
polymorphism, encapsulation, and inheritance working together:
Shape
Draw()
Triangle
Draw()
Rectangle
Draw()
Circle
Draw()
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
18
- 19. Objects And Classes
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
19
- 20. Defining a Class
• The syntax to define a class:
class <class_name>
{
……
}
• An example to define a class:
class SimpleCalculator {
}
• In the preceding code snippet is used to define SimpleCalulator class.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
20
- 21. Creating an Object
• The syntax to create an object:
<classname> <object ref variable> = new <classname>();
• An example to create an object:
SimpleCalculator obj=new SimpleCalculator();
• In the preceding code snippet, a object reference variable named obj
of type SimpleCalculator is created. The new operator creates a new
SimpleCalculator object on the heap memory and assigns this object
to the reference variable, obj.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
21
- 22. Creating an Object (Contd.)
• You can also assign null to an object reference variable as shown in
the following code snippet:
SimpleCalculator obj=null;
• The preceding code snippet creates an object reference variable but it
does not refers any object. Here, only a space for the object reference
variable is created but an actual SimpleCalculator object is not
created.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
22
- 23. Instance Variable
• Instance variable is a variable defined inside the class, but outside any
method.
• Each instantiated object has a separate copy of instance variable.
• If the instance variables are not initialized, they will have the default value.
• An example to create instance variable:
class SimpleCalculator {
int operand1, operand2,result;
}
• In the preceding code snippet, operand1,operand2, and result are the
instance variables of SimpleCalculator class.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
23
- 24. Method
• A method is a block of statements that has a name and can be
executed by calling.
• A method is defined to preform certain task.
• The syntax to define a method:
<returntype> <methodname>(parameterlist){
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
24
- 25. Method (Contd.)
• The different types of methods are:
• Method without return type and without parameter
• Method without return type and with parameter
• Method with return type and without parameter
• Method with return type and with parameter.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
25
- 26. Method (Contd.)
• An example to define a method without return type and without
parameter:
void sum(){
int a=10;
int b=20;
int result=a+b;
System.out.println(“The sum:”+result);
}
• If a method does not return any value, then the return type should be
set to void.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
26
- 27. Method (Contd.)
• An example to define a method without return type and with
parameter:
void sum(int a, int b){
int result=a+b;
System.out.println(“The sum :”+result);
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
27
- 28. Method (Contd.)
• An example to define a method with return type and without
parameter:
int sum(){
int a=10;
int b=20;
int result=a+b;
return result;
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
28
- 29. Method (Contd.)
• An example to define a method with return type and with parameter:
int sum(int a, int b){
int result=a+b;
return result;
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
29
- 30. Method (Contd.)
• An example to define a instance method and call the method using object:
public class SimpleCalculator {
int sum(int a, int b){
int result=a+b;
return result;
}
public static void main(String args[]){
SimpleCalculator obj=new SimpleCalculator();
int rVal=obj.sum(10,20);
System.out.println("The sum:"+rVal);
}
}
• In the preceding code, the dot operator is used to invoke the
instance method.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
30
- 31. Method (Contd.)
• You can also pass reference variables as arguments to a method as
shown in the following code:
class Points{
int x=10,y=-5;
}
public class MethodPORDemo {
void changePoints(Points p){
System.out.println("x="+p.x);
System.out.println("y="+p.y);
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
31
- 33. Method (Contd.)
• The preceding code output will be:
x=10
y=-5
x=-5
y=10
• A method can also return a refernce type as shown in the following
code:
class Circle {
int radius=10;
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
33
- 34. Method (Contd.)
public class MethodRODemo {
Circle getCircleObject(Circle cObj) {
cObj.radius=20;
return cObj;
}
public static void main(String args[]){
MethodRODemo mObj=new MethodRODemo();
Circle c1=new Circle();
System.out.println("Radius="+c1.radius);
Circle c2=mObj.getCircleObject(c1);
System.out.println("Radius="+c2.radius);
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
34
- 35. Method (Contd.)
• The preceding code output will be:
Radius=10
Radius=20
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
35
- 36. Constructor
• Constructor is a special type of method that has the same name of
the class and does not has any return type.
• The constructor is automatically called when an object is created.
• The constructor is used to initialize the instance variable of a class.
• An example to define a constructor without parameter:
class SimpleCalculator {
int operand1,operand2;
SimpleCalculator(){
operand1=5;
operand2=6;
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
36
- 37. Constructor (Contd.)
• An example to define a parameterized constructor:
class SimpleCalculator {
int operand1,operand2;
SimpleCalculator(int oprd1,int oprd2){
operand1=oprd1;
operand2=oprd2;
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
37
- 38. Constructor (Contd.)
public static void main(String args[]){
SimpleCalculator obj1=new
SimpleCalculator(10,20);
SimpleCalculator obj2=new
SimpleCalculator(1,2);
System.out.println(obj1.operand1);
System.out.println(obj2.operand1);
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
38
- 39. Constructor (Contd.)
• The preceding code output will be:
10
1
• If a constructor is not defined explicitly, the compiler adds
an default constructor.
• A default constructor is a constructor without arguments.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
39
- 40. Constructor (Contd.)
• Consider the following code:
public class ConstructorDemo {
int x;
public ConstructorDemo(int a) {
x=a;
}
public static void main(String args[]){
ConstructorDemo cdObj=new ConstructorDemo();
}
}
• The preceding code will generate a compilation error, as the class
does not defines a no argument constructor.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
40
- 42. Package
• A package is a namespace that organizes a set of related types, such as
classes and interfaces.
• The syntax to create a package is:
package <package name>;
• An example to create package:
package test;
class PackageDemo
{
}
• In the preceding code snippet, the PackageDemo class belongs to test
package.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
42
- 43. Package
• A class can access the classes in another package by importing the
required package.
• The syntax to import a package is:
import <package name>.*;
• An example to import a package:
import test.*;
class Demo{
}
• In the preceding code snippet, the Demo class can access the classes
inside test package.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
43
- 44. Access Modifiers
• Access level modifiers determine whether other classes can use a
particular field or invoke a particular method.
• Java has four access control levels, public, protected, default, and
private.
• But there are only three access modifiers, public, protected, and
private.
• When any of the three access modifier is not specified then the
default access control level is specified.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
44
- 45. Access Modifiers (Contd.)
• The following table shows the access to members permitted by each
modifier:
Modifier Class Package Subclass
public Y Y Y
protected Y Y Y
no modifier Y Y N
private Y N N
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
45
- 46. Access Modifiers (Contd.)
• All the four access modifiers can be used with the instance variables.
• The top level class can use only public and default modifier.
• The constructor can use all the four access modifiers.
• An example to work with access modifier:
package pack1;
public class Test {
public int testA;
private int testB;
protected int testC;
int testD;
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
46
- 48. Access Modifiers (Contd.)
public void testPrint(){
System.out.println("public method testPrint");
}
private void testDisplay(){
System.out.println("private method testDisplay");
}
protected void testPut(){
System.out.println("protected method testPut");
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
48
- 49. Access Modifiers (Contd.)
package pack1;
class Sample {
public int sampleA;
private int sampleB;
protected int sampleC;
public Sample(int a,int b, int c){
sampleA=a;
sampleB=b;
sampleC=c;
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
49
- 50. Access Modifiers (Contd.)
public void samplePrint(){
System.out.println("public method samplePrint");
}
private void sampleDisplay(){
System.out.println("private method sampleDisplay");
}
protected void samplePut(){
System.out.println("protected method samplePut");
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
50
- 51. Access Modifiers (Contd.)
package pack2;
import pack1.*;
public class Demo {
public static void main(String args[]){
Test testObj=new Test(10,20,30,40);
System.out.println(testObj.testA);
testObj.testPrint();
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
51
- 52. Access Modifiers (Contd.)
• The preceding code output will be:
10
public method testPrint
• In the preceding code, inside the Demo class Sample class cannot be
accessed because the Sample class has default access control.
• Similarly, the variable, testB, testC, and testD are not accessible as
they have private, protected, and default access control.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
52
- 53. Encapsulation Implementation
• To create a Java program that supports maintainability, flexibility, and
extensibility, then it must include encapsulation.
• Encapsulation is implemented by:
• Protecting the instance variable.
• Make public accessor methods to access the instance variable.
• An example to implement encapsulation:
class Rectangle {
private int length;
private int breadth;
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
53
- 54. Encapsulation Implementation (Contd.)
public int getLength() {
return length;
}
public void setLength(int l) {
length = l;
}
public int getBreadth() {
return breadth;
}
public void setBreadth(int b) {
breadth = b;
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
54
- 55. Encapsulation Implementation (Contd.)
public class EncapsulationDemo {
public static void main(String args[]){
Rectangle r=new Rectangle();
r.setLength(10);
r.setBreadth(20);
}
}
• The preceding code forces to access the instance variable to be
accessed using methods. This methodology allows to modify the
implementation later without affecting the other classes which uses
the instance variables.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
55
- 57. Method Overloading
• If two or more method in a class have same name but different
parameters, it is known as method overloading.
• Method overloading is one of the ways through which Java supports
polymorphism.
• An example to implement method overloading:
public class SimpleCalculator {
void add(int a, int b){
int result=a+b;
System.out.println("The sum:"+result);
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
57
- 58. Method Overloading (Contd.)
void add(int a, int b,int c){
int result=a+b+c;
System.out.println("The sum:"+result);
}
}
void add(double a, double b){
double result=a+b;
System.out.println("The sum:"+result);
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
58
- 59. Method Overloading (Contd.)
public static void main(String args[]){
SimpleCalculator obj=new SimpleCalculator();
obj.add(1,2);
obj.add(1,2,3);
obj.add(23.5,34.7);
}
}
• The preceding code output will be:
The sum:3
The sum:6
The sum:58.2
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
59
- 60. Method Overloading (Contd.)
• The following code snippet is a non-example of method overloading:
public void print(){
}
private void print(){
}
• The following code snippet is an example of method overloading:
public void print(){
}
private void print(int x){
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
60
- 61. Method Overloading (Contd.)
• The following code snippet is a non-example of method overloading:
public void print(){
}
private int print(){
}
• The following code snippet is an example of method overloading:
public void print(){
}
private int print(int x){
return 1;
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
61
- 62. Constructor Overloading
• When more than one constructor is defined in a class, it is known as
constructor overloading.
• An example to implement constructor overloading:
public class SimpleCalculator {
int operand1,operand2,result;
SimpleCalculator(){
operand1=1;
operand2=2;
}
SimpleCalculator(int oprd1, int oprd2){
operand1=oprd1;
operand2=oprd2;
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
62
- 63. Constructor Overloading (Contd.)
void sum(){
result=operand1+operand2;
System.out.println("The sum: "+result);
}
public static void main(String args[]){
SimpleCalculator obj1=new SimpleCalculator();
obj1.sum();
SimpleCalculator obj2=new SimpleCalculator(12,45);
obj2.sum();
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
63
- 64. Constructor Overloading (Contd.)
• The preceding code output will be:
The sum: 3
The sum: 57
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
64
- 65. Variable Argument
• Variable argument allows the method to accept zero or multiple
arguments.
• The syntax to define a variable argument method:
<return type> <method name>(<data type>…
<variablename>){
}
• An example to define a variable argument method:
void display(int…a){
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
65
- 66. Variable Argument (Contd.)
• An example to implement variable argument:
public class Demo{
void display(int...a){
int count=0;
for(int x:a){
count++;
}
System.out.println("The number arguments:"+count);
}
public static void main(String args[]){
Demo obj=new Demo();
obj.display();
obj.display(1);
obj.display(1,2);
obj.display(1,2,3);
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
66
- 67. Variable Argument (Contd.)
• The preceding code output will be:
The number arguments:0
The number arguments:1
The number arguments:2
The number arguments:3
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
67
- 68. Variable Argument (Contd.)
• Rules to work with variable argument:
• A method can have only one variable argument parameter.
• The variable argument must be the last parameter of the method.
• The following code snippet is a non-example of variable argument
implementation:
void display(int...a, int...b){ }
void display(int...a, int b){ }
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
68
- 69. Variable Argument and Overloading
• Consider a scenario, where you need to pass many instance of same
object to a method. In such situation, the programmer has two
choices:
• Create an overloaded method
• Create a method that accepts array or other collections
• However, at compile time if you do not know how many instance will
be used creating an overloaded method becomes difficult.
• Working with arrays and other collections makes the code lengthy
and complex.
• Therefore, variable arguments were introduced to simplify the task of
the programmer.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
69
- 70. Use of this Keyword
• The this keyword is used to refer the current object in the code.
• Consider the following code:
public class SimpleCalculator {
SimpleCalculator(int operand1, int operand2){
}
• In the preceding code snippet, the instance variable and the
parameter variable of the constructor have the same name.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
70
- 71. Use of this Keyword (Contd.)
• In such situation, to use the instance variable inside the constructor
the this keyword is used as shown in the following code snippet:
SimpleCalculator(int operand1, int operand2){
this.operand1=operand1;
this.operand2=operand2;
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
71
- 72. Use of this Keyword (Contd.)
• An example to work with this keyword:
public class SimpleCalculator {
int operand1,operand2,result;
SimpleCalculator(){
operand1=10;
operand2=20;
}
SimpleCalculator(int operand1, int operand2){
this.operand1=operand1;
this.operand2=operand2;
}
int sum(){
result=operand1+operand2;
return result;
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
72
- 73. Use of this Keyword (Contd.)
public static void main(String args[]){
SimpleCalculator obj=new SimpleCalculator(102,52);
int rVal=obj.sum();
System.out.println("The sum:"+rVal);
}
}
• The preceding code output will be:
The sum:154
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
73
- 74. Use of this Keyword (Contd.)
• An example to work with constructor chaining using this keyword:
class Flower{
String flowerName;
Flower(){
this("Rose");
}
Flower(String flowerName){
this.flowerName=flowerName;
}
}
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
74
- 75. Use of this Keyword (Contd.)
public class ConstructorDemo {
public static void main(String args[]){
Flower fObj=new Flower();
System.out.println(fObj.flowerName);
}
}
• The preceding code output will be:
Rose
• The constructor chaining avoids code duplication.
• Note: The this() statement should be the first line in the constructor
definition.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
75
- 76. Summary
• You have learnt that:
• The object-oriented is a programming paradigm where the program logic and
data are weaved.
• The characteristic of OOPs are class, object, polymorphism, encapsulation,
and inheritance.
• An entity that has state and behavior is known as an object.
• A class is a collection of objects and a corresponding set of methods.
• Encapsulation is the mechanism that binds together code and the data it
manipulates, and keeps both safe from outside interference and misuse.
• Inheritance is the process by which one object acquires the properties of
another object.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
76
- 77. Summary (Contd.)
• Polymorphism is the capability of an action or method to do different things
based on the object that it is acting upon.
• Define class, constructor and method.
• Create object and instance variable.
• A package is a namespace that organizes a set of related types, such as classes
and interfaces.
• Access level modifiers determine whether other classes can use a particular
field or invoke a particular method.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
77
- 78. Summary
• If two or more method in a class have same name but different parameters, it
is known as method overloading.
• When more than one constructor is defined in a class, it is known as
constructor overloading.
• Variable argument allows the method to accept zero or multiple arguments.
© People Strategists - Distribution is strictly prohibited -
www.peoplestrategists.com
78