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

Presentation 3

The document outlines key concepts of Object-Oriented Programming (OOP) in Java, including classes, objects, methods, and constructors. It explains the structure of UML class diagrams and provides examples of creating and using classes such as Bicycle and LibraryCard. Additionally, it covers the importance of access modifiers, passing objects to methods, and the organization of Java programs into packages for reusability.

Uploaded by

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

Presentation 3

The document outlines key concepts of Object-Oriented Programming (OOP) in Java, including classes, objects, methods, and constructors. It explains the structure of UML class diagrams and provides examples of creating and using classes such as Bicycle and LibraryCard. Additionally, it covers the importance of access modifiers, passing objects to methods, and the organization of Java programs into packages for reusability.

Uploaded by

kakefon876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 92

IT 214

Object
Oriented
Programming
Dr. Abdulaziz Saleh Algablan
[email protected] :Email
2024
Outline
• Defining and Using Classes
• Defining and Using Multiple Classes
• Matching Arguments and Parameters
• Passing Objects to a Method
• UML Class Diagram
• Methods
• Constructors
• Access Modifiers
• This keyword
• Software reusability
Classes and Objects
• In the Java, we must provide a definition, called a class to be able to
create an object.
• A class is a kind of mold or template that dictates what objects can
and cannot do.
• An object is called an instance of a class.
• An object is an instance of exactly one class.
• An object is comprised of
• data (attributes)
• operations (methods) that manipulate these data.
• A program written in object-oriented style will consist of interacting
objects.
UML Class Diagram Notation
• UML stands for Unified Modeling
Language.
• The top section is used to name the
class.
• The second one is used to show the
attributes of the class.
• The third section is used to describe the
operations (methods) performed by the
class.
• The fourth section is optional to show
any additional components.
UML Class Diagram
public class Book { public class Person {

private String name;


private String name; private int age;
private String publisher; public Person(String initialName) {
private Person author; this.name = initialName;
this.age = 0;
}

public void printPerson() {


// constructors and methods
System.out.println(this.name + ", age " +
} this.age + " years");
}

public String getName() {


return this.name;
}
}
The bicycle class
• Suppose we want to develop a program that tracks the bicycles by
assigning to them some form of identification number along with the
relevant information:
• the owner’s name and phone number.
• There’s no such Bicycle class among the standard classes, of course,
so we need to define one ourselves.
The main method
class BicycleRegistration {
public static void main(String[] args) {
Bicycle bike1, bike2;
String owner1, owner2;
bike1 = new Bicycle( ); //Create and assign values to bike1
bike1.setOwnerName("Adam Smith");
bike2 = new Bicycle( ); //Create and assign values to bike2
bike2.setOwnerName("Ben Jones");
//Output the information
owner1 = bike1.getOwnerName( );
owner2 = bike2.getOwnerName( );
System.out.println(owner1 + " owns a bicycle.");
System.out.println(owner2 + " also owns a bicycle.");
} }
The main method
Implementation of Bicycle Class
• From the test class (BicycleRegistration), you can guess:
• The attributes
• The methods
UML class Diagram
• The dependency diagram between the two classes is as follows:
Java Source Files
• For this sample program, we can create two classes:
• BicycleRegistration, which has the main method
• Bicycle
• So, there are two source files for this program:
Java Source Files
• Remember:
• Only one class can be public class.
• The public class name should be identical to the java file name (without
“.java”)
• The main method must be in a public class
Java Source Files
• Remember:
• The command “javac BicycleRegistration.java” complies java source file and
will generate “BicycleRegistration.class”
• Because Bicycle class is used inside BicycleRegistration.java, Java automatically compiles
it also.
• Then, The command “java BicycleRegistration” is used to run the file in JVM.
Java Source Files – option 2
• Another option, we can create two classes in one Java file:
• BicycleRegistration class, which has the main method
• Bicycle class
• Since BicycleRegistration has the main method, it should be public class.
While the Bicycle class must not be be public class
• So, there are one source file for this program
• The file must be named “BicycleRegistration.java”
Java Source Files – option 2
• To have multiple classes in one Java file, each class should be written
separately (not included in other classes)
• For example, the BicycleRegistration.java can have:
public class BicycleRegistration {
// BicycleRegistration start
// code for BicycleRegistration class
} // BicycleRegistration end
class Bicycle { // start
} // end
Java Source Files – option 2
• Be careful of including the Bicycle class the BicycleRegistration as:
public class BicycleRegistration {
// BicycleRegistration start
// code for BicycleRegistration class
class Bicycle { // start
} // end
} // BicycleRegistration end

• Now, Bicycle is an inner class of BicycleRegistration.


• This will be covered later.
Bicycle Data Members
• What would be the data members of Bicycle objects?
• We need to know the owner’s name of every Bicycle object, so we’ll define one data
member to store the owner’s name. The data members of a class are declared
within the class declaration.
• Here’s how we define the data member ownerName of the Bicycle class:
class Bicycle {
; private String ownerName

,definitions for the constructor//

getOwnerName, and setOwnerName methods come here//


}
Bicycle Content
Bicycle Data Members
• The syntax for the data member declaration is:
<modifier-list> <data type> <name> ;
• <modifier-list> designates different characteristics of the data
member
• <data type> the class name or primitive data type
• <name> the name of the data member
Bicycle Data Members
• The data member has one modifier named private.
• This modifier is called an accessibility modifier, or a visibility modifier,
and it restricts who can have a direct access to the data member.
• If the modifier is private, then only the methods defined in the class
can access it directly
• If the modifier is public, other classes can access it.
• See next example.
Bicycle class
class Bicycle {
// Data Member
private String ownerName; // This is PRIVATE
public String brandName; // this is PUBLIC
//Constructor: Initialzes the data member
public Bicycle( ) {
ownerName = "Unknown";
}
//Returns the name of this bicycle's owner
public String getOwnerName( ) { return ownerName; }
//Assigns the name of this bicycle's owner
public void setOwnerName(String name) {
ownerName = name:
}
}
The main method
class BicycleRegistration {
public static void main(String[] args) {
Bicycle bike1, bike2;
String owner1, owner2;
bike1 = new Bicycle( ); //Create and assign values to bike1
//bike1.setOwnerName("Adam Smith");
bike1.ownerName = “Adam Smith”; // THIS CAUSES AN ERROR
bike1.brandName = “Trek”; // THIS IS OK
bike2 = new Bicycle( ); //Create and assign values to bike2
bike2.setOwnerName("Ben Jones");
//Output the information
owner1 = bike1.getOwnerName( );
owner2 = bike2.getOwnerName( );
System.out.println(owner1 + " owns a bicycle.");
System.out.println(owner2 + " also owns a bicycle.");
Method vs. Attribute Call
• Calling a method requires round brackets “( )”
• For example:
bike2.setOwnerName("Ben Jones");
• Calling an attributes does not require brackets.
• For example:
bike1.ownerName = “Adam Smith”;
Bicycle Data Members -
setOwnerName
• The general syntax correspond to the actual elements in the
setOwnerName method:
Bicycle Data Members -
setOwnerName
• A method that does not return a value is declared as void. It is called a
void method.
• The accessibility modifier for the setOwnerName method is declared
as public. This means the program that uses the Bicycle class can
access, or call, this method.
• It is possible (and could be useful) to declare a method as private. If a
method is declared as private, then it cannot be called from the pro
gram that uses the class
Constructor
• The first method defined in the Bicycle class is a special method called
a constructor.
• A constructor is a special method that is executed when a new
instance of the class is created, that is, when the new operator is
called.
• Here’s the constructor for the Bicycle class:
{ ) (public Bicycle
;"ownerName = "Unassigned
}
Constructor
Class Diagram for Bicycle Class
• A class diagram of the Bicycle class with two methods and one data
member
Exercisers
• Extend the Bicycle class by adding the second data member tagNo of type String. Declare this
data member as private.
• Add a new method to the Bicycle class that assigns a tag number. This method will be called as
follows:
Bicycle bike;
bike = new Bicycle( );
//... Some code
bike.setTagNo("2004–134R");
• Add a another rmethod to the Bicycle class that returns the bicycle’s tag number. This method
will be called as follows:
Bicycle bike;
bike = new Bicycle( );
//... Some code
bike.getTagNo();
Bicycle class
class Bicycle {
// Data Member
private String ownerName; // This is PRIVATE
private String tagNo;
public String brandName; // this is PUBLIC
//Constructor: Initialzes the data member
public Bicycle( ) {
ownerName = "Unknown";
}
//Returns the name of this bicycle's owner
public String getOwnerName( ) { return ownerName; }
//Assigns the name of this bicycle's owner
public void setOwnerName(String name) {
ownerName = name:
}
}
A SecondMain class
class SecondMain
//This sample program uses both the Bicycle and Account classes
{ public static void main(String[] args){
;Bicycle bike
;Account acct
;"String myName = "Jon Java
;bike = new Bicycle( ); bike.setOwnerName(myName)
;acct = new Account( ); acct.setOwnerName(myName)
;acct.setInitialBalance(250.00)
;acct.add(25.00); acct.deduct(50)
Output some information//
;System.out.println(bike.getOwnerName() + " owns a bicycle and")
+ )(System.out.println("has $ " + acct.getCurrentBalance
;)"left in the bank "
UML class diagram for SecondMain
class
Bicycle Data Members - Objects
• Data members can be objects, in addition to being primary Java data types.
• The bicycle instance consists of two tires.
Bicycle Data Members - Objects
class Bicycle {
class Tire {
// Data Member
// Data Member
private String ownerName; // This is PRIVATE
private int sizeInInch; // This is PRIVATE
public String brandName; // this is PUBLIC
public String brandName; // this is PUBLIC
public Tire firstTire;
//Constructor: Initialzes the data member
public Tire secondTire;
public Tire( ) {
//Constructor: Initialzes the data member
sizeInInch = 16;
public Bicycle( ) {
ownerName = "Unknown"; }

} public int getSizeInInch( ) { return sizeInInch; }

//Returns the name of this bicycle's owner public void setSizeInInch(int aNumber) {

public String getOwnerName( ) { return ownerName; }


sizeInInch = aNumber :

//Assigns the name of this bicycle's owner }


public void setOwnerName(String name) {
ownerName = name: }
}
}
Matching Arguments and
Parameters
• Consider the following sample class that includes a method named
compute:
class Demo {
//...
public void compute(int i, int j, double x) {
//method body
}
//...
}

• This method has three parameter


• two int and one double.
Matching Arguments and
Parameters
• When we call the compute method, we must pass three values.
• The values we pass must be assignment-compatible with the
corresponding parameters.
• For example, it is not okay to pass a double value to an int parameter.
Here are some valid calls from the main method:
Matching Arguments and
Parameters
class MyMain {
{ public static void main(String[] arg)
;)(Demo demo = new Demo
;int i, k, m
;i = 12; k = 10; m = 14
demo.compute(3, 4, 5.5); // all values
demo.compute(i, k, m); // all variables
demo.compute(m, 20, 40); // mixing variables and values
}
}
Arguments and Parameters
• In the statement: demo.compute(m, 20, 40);
• the values m, 20, and 40 are called arguments.
• A parameter is a placeholder in the called method to hold the value of
a passed argument.
• The arguments and parameters are matched in left-to-right order
• Note: Java does not assign default values if empty argument is passed
such as:
• demo.compute(m, 20, ); // ERROR
• demo.compute(m,,40 ); // ERROR
Passing Objects to a Method
• Objects, like primitive types, can be passed as parameters to methods
in Java.
• When passing an object as a parameter to a method, a reference to
the object is passed rather than a copy of the object itself.
• This means that any modifications made to the object within the
method will have an impact on the original object.
Passing Objects to a Method
Public class Student {
//Constructor
public Student( ) {
name = "Unassigned"; email = "Unassigned"; }
//Returns the email of this student
public String getEmail( ) { return email; }
//Returns the name of this student
public String getName( ) { return name; }
//Assigns the email of this student
public void setEmail(String address) { email = address; }
//Assigns the name of this student
public void setName(String studentName) {name = studentName; }
}
Passing Objects to a Method – cont.
{ class LibraryCard
Data Members //
student owner of this card//
private Student owner; //number of books borrowed
;private int borrowCnt
Constructor//
{ ) (public LibraryCard
;owner = null
} ;borrowCnt = 0
Passing Objects to a Method – cont.
numOfBooks are checked out//
{ public void checkOut(int numOfBooks)
} ;borrowCnt = borrowCnt + numOfBooks
Returns the number of books borrowed //
public int getNumberOfBooks( ) { return borrowCnt; }
Returns the name of the owner of this card //
) (public String getOwnerName
{
};) (return owner.getName
Sets owner of this card to student //
{ public void setOwner(Student student)
;owner = student
}
Returns the string representation of this card //
public String toString( ) {
}return ”---”;}
Passing Objects to a Method – cont.
class Librarian {
public static void main(String[] args) {
Student student;
LibraryCard card1, card2;
student = new Student( );
student.setName("Jon Java"); student.setEmail("[email protected]");
card1 = new LibraryCard( );
card1.setOwner(student);

card1.checkOut(3);
card2 = new LibraryCard( );
card2.setOwner(student); //the same student is the owner
//of the second card, too
System.out.println("Card1 Info:"); System.out.println(card1.toString() + "\n");
System.out.println("Card2 Info:");
System.out.println(card2.toString() + "\n"); }
}
.Passing Objects to a Method – cont
Remember
• When we pass an object to a method, we are actually passing the
address, or reference, of an object to the method.
• It is possible to return the Student object itself by defining the
following method in the LibraryCard class:
public Student getOwner( ) {
return owner;
}
Program Modules in Java
• Java programs are written by combining new methods and classes
that you write + predefined ones available in the Java Application
Programming Interface (API) and in various other class libraries.
• Related classes are typically grouped into packages so that they can
be imported into programs and reused
• package package_name;
• The Java API provides a rich collection of predefined classes.
• import java.util.Scanner;
Package and Access Modifiers
• Any Java members such as class or methods or data members when not
specified with any access modifier they are by default considered as
default access modifiers.
• These methods or data members are only accessible within the same
package and they cannot be accessed from outside the package.
• Package-level accessibility provides more visibility than a private access
modifier. But this access modifier is more restricted than protected and
public access modifiers.
• we conclude that the default access modifier members can be accessed
only within the same package and cannot be accessed from outside the
package.
Declaring Methods
• Generally, method declarations have six components:
• Modifiers—such as public, private, and others.
• Return type—the data type of the value returned by the method, or void if
the method does not return a value.
• Method name—the rules for field names apply to method names as well, but
the convention is a little different.
• Parameter list in parenthesis—a comma-delimited list of input parameters,
preceded by their data types, enclosed by parentheses, (). If there are no
parameters, you must use empty parentheses.
• An exception list—to be discussed later.
• Method body, enclosed between braces—the method's code, including the
declaration of local variables, goes here.
Methods
• You can send a message only to the classes and objects that
understand the message you send.
• For a class or an object to process the message it receives, it must
possess a matching method.
• A method is a sequence of instructions that a class or an object
follows to perform a task.
• A method defined for a class is called a class method, and a method
defined for an object is an instance method.
• A value passed to an object is called an argument of a message
Access Modifiers
• In Java, methods and data members can be encapsulated by the
following four access modifiers:
1. private (accessible within the class where defined)
2. default or package-private
i. when no access modifier is specified
ii. Allow package level access
3. protected (accessible only to classes that subclass your class directly within
the current or different package)
4. public (accessible from any class)
Instance method vs Static method
• A method defined for a class is called a class method or a static
method.
• Static methods:
• can access the static variables and static methods directly.
• can’t access instance methods and instance variables directly.
• A method defined for an object is an instance method.
• Instance method
• Access the instance methods and instance variables directly.
• Access static variables and static methods directly.
When to Use Static Methods?
• Using static methods makes sense when we are developing methods
with standard behavior that operates on input arguments.
• Declaring main as static allows the JVM to invoke main without
creating an object of the class.
• Static keyword allows methods to be accessed via the class name
Math and a dot (.) separator.
Calling Static Methods & Static
Fields
• Cass’s static methods and static field are called by specifying the name
of the class in which the method is declared, followed by a dot (.) and
the method/field name.
• Math.max(55, 1.6666);
Static method
• Example of standard behaviour that operates on their input
arguments
Overloading Methods
• Java supports overloading of methods.
• Java can distinguish between methods with
different method signatures.
• This means that methods within a class can
have the same name if they have different
parameter lists.
• For Example: draw method is overloaded in
the DataArtist class.
Overloading Methods
• The order of parameter types cause a new version
• This is fine, for example:

void aMethod(){ }
void aMethod(int a ){ }
void aMethod(double a ){ }
void aMethod(int a, double d ){ }
void aMethod(double a, int d ){ }
Overloading Methods
• Methods cannot be overloaded by changing their return type.
• For example:

String printMe()
{
return ”I am a String";
}
int printMe()
{
return 0;
}
• This causes a compilation error.
Overloading Methods
• Its fine when the return type and a parameter has been changed.
• For example:

String printMe()
{
return ”I am a String";
}
int printMe(int a)
{
return 0;
}
Method-Call Stack and Activation
Records
• A call to method creates a stack memory for the method
• Stack follows Last-in, first-out (LIFO) data structures
• The first item is pushed down to the bottom of the stack.
• The last item pushed onto the top of the stack.
• the last item is the first item popped from the stack.

CC BY-SA by Unknown Author is licensed under This Photo


Method-Call Stack and Activation
Records
• When a program calls a method, the called method must know how to
return to its caller, so the return address of the calling method is pushed
onto the method-call stack
• If a series of method calls occurs, the successive return addresses are
pushed onto the stack in last-in, first-out order
• The method-call stack also contains the memory for the local variables
(including the method parameters) used in each invocation of a method
• When a method returns to its caller, the stack frame for the method call
is popped off the stack and those local variables are no longer known to
the program
Method-Call Stack and Activation
Records
static int getANumber( )
{ int a =100;
return a;
}
public static void main(String [] arg)
{
int x = 10;
int y = x;
int w = getANumber();

x = 10
}
main Stack
Method-Call Stack and Activation
Records
static int getANumber( )
{ int a =100;
return a;
}
public static void main(String [] arg)
{
int x = 10;
int y = x;
int w = getANumber();
y = 10
x = 10
}
main Stack
Method-Call Stack and Activation
Records
static int getANumber( )
{ int a =100;
return a;
}
Stack
public static void main(String [] arg) created
{
int x = 10;
int y = x; w=
int w = getANumber(); y = 10
x = 10

} main Stack getANumber Stack


Method-Call Stack and Activation
Records
static int getANumber( )
{ int a =100;
return a;
}
public static void main(String [] arg)
{
int x = 10;
int y = x;
w=
int w = getANumber();
y = 10
x = 10 a = 100
}
main Stack getANumber Stack
Method-Call Stack and Activation
Records
static int getANumber( )
{ int a =100;
return a;
}
public static void main(String [] arg) Stack
deleted
{
int x = 10;
int y = x;
w = 100
int w = getANumber();
y = 10
x = 10
}
main Stack getANumber Stack
Scope of Declarations
• Declarations of variables introduce names that can be used to refer to
classes, methods, variables and parameters.
• The scope of a declaration is the portion of the program that can refer
to the declared entity by its name
• Such an entity is said to be “in scope” for that portion of the program
• For example, the scope of declaration of a class variable is
• Static and none-static methods.
• Constructors.
Scope of Declarations
• Basic scope rules:
• The scope of a parameter declaration is the body of the method in which the
declaration appears.
• The scope of a local-variable declaration is from the point at which the
declaration appears to the end of that block.
• The scope of a local-variable declaration that appears in the initialization
section of a for statement’s header is the body of the for statement and the
other expressions in the header.
• A method or field’s scope is the entire body of the class.
Scope of Declarations
• Any block may contain variable declarations
• If a local variable or parameter in a method has the same name as a
field of the class, the field is hidden until the block terminates
execution called shadowing.
• A variable which is redefined in a statement inside a method will be
point to last declaration occurs in
• Previous statements in the method body
• Then, parameter lists
• Then, instance & class variables
Scope of Declarations
{ public class ClassA { public class Test

} {)(ClassA public static void main(String []


ClassA(int aNumber) { arg)

{ ;ClassA a1 = new ClassA(20)

;aNumber = aNumber ;System.out.println(a1.aNumber)

} }

;int aNumber = 10
;protected int bNumber
;int cNumber
} }
Scope of Declarations
{ public class ClassA { public class Test

} {)(ClassA public static void main(String [] arg)


{
ClassA(int a)
;ClassA a1 = new ClassA(20)
{
;System.out.println(a1.aNumber)
;int aNumber = a
}
}
;int aNumber = 10
;protected int bNumber
;int cNumber
} }
Scope of Declarations
{ public class ClassA { public class Test

} {)(ClassA public static void main(String []


ClassA(int a) { arg)

{ ;ClassA a1 = new ClassA(20)

;aNumber = 30 ;System.out.println(a1.aNumber)

;int aNumber = a }

}
;int aNumber = 10
;protected int bNumber
;int cNumber
} }
Scope of Declarations
Scope of Declarations
Constructors
• A constructor in Java is a special method that is used to initialize
objects.
• The constructor is called when an object of a class is created.
• It can be used to set initial values for object attributes.
• It is possible to define more than one constructor to a class.
• Multiple contractors are called overloaded constructors.
• It is a good idea to define multiple constructors to a class.
Constructors
• Note: It is not necessary to write a constructor for a class.
• Java compiler creates a default constructor (constructor with no-
arguments) if your class doesn’t have any.
Constructors vs. Methods
• Constructors must have the same name as the class within which it is
defined it is not necessary for the method.
• Constructors do not return any type while method(s) have the return
type or void if does not return any value.
• Constructors are called only once at the time of object creation while
method(s) can be called any number of times.
Usage of java this keyword
• Every object can access a reference to itself with keyword this
(sometimes called the this reference).
z
Usage of java this keyword

• this can be used to refer current class instance variable.


• this can be used to invoke current class method (implicitly).
• this() can be used to invoke current class constructor.
• this can be passed as an argument in the method call.
• this can be passed as argument in the constructor call.
• this can be used to return the current class instance from the method.
this keyword
public clsss Person
{
public Person(String name, int numberOfCarsOwned)
{
this(name);
this.numberOfCarsOwned = numberOfCarsOwned;
Person thisPerson = this;
doSomething(thisPerson);
}
}
this keyword
public clsss Person
{
public Person(String name, int numberOfCarsOwned)
{
this(name);
this.numberOfCarsOwned = numberOfCarsOwned;
Person thisPerson = this;
doSomething(thisPerson);
}
public Person(String name)
{
numberOfCarsOwned = 0;
}
Public void doSomething(Person aPerson)
{
// code here.
}
}
Usage of java this
keyword
Pass-By-Value vs. Pass-By-Reference
• Two ways to pass arguments in method calls:
• pass-by-value.
• pass-by-reference.
• When an argument is passed by value, a copy of the argument’s value is
passed to the called method.
• The called method works exclusively with the copy.
• Changes to the called method’s copy do not affect the original variable’s value in the
caller.
• When an argument is passed by reference, the called method can access the
argument’s value in the caller directly and modify that data, if necessary.
• passed by reference improves performance by eliminating the need to copy possibly
large amounts of data.
Pass-By-Value vs. Pass-By-Reference
• Java does not allow you to choose pass-by-value or pass-by-reference
• method call can pass two types of values to a method
• Copies of primitive values
• Copies of references to objects.
• Objects themselves are not passed to methods.
• If you modify a reference-type parameter so that it refers to another object, only
the parameter refers to the new value.
• Although an object’s reference is passed by value, a method can still interact with
the referenced object by calling its public methods using the copy of the object’s
reference.
• The parameter in the called method and the argument in the calling method refer to
the same object in memory.
Java Static Block

• There are cases in which we may need to do more than a simple


assignment to initialize a class variable.
• If we need to perform more than a simple assignment to initialize a
class variable, then we define a static initializer.
• A static initializer is a code that gets executed when a class is loaded
into the Java system.
Java Static Block

• A static block helps to initialize the static data members, just like
constructors help to initialize instance members.

public class Demo {


static int a;
static int b;
static
{
a = 10;
b = 20;
}
public static void main(String args[]) {
System.out.println("Value of a = " + a);
System.out.println("Value of b = " + b);
}
}
Software Reusability
• Statements in method bodies are written only once, are hidden from
other methods and can be reused from several locations in a
program.
• Existing methods can be used as building blocks to create new
programs
• It’s logical to utilize existing classes and methods rather than building
new customized code.
• Dividing a program into meaningful methods makes the program
easier to debug and maintain.
• The end

You might also like