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

Basic Object Oriented Programming Concept

The document provides an overview of Object-Oriented Programming (OOP) concepts, contrasting them with procedural programming. It explains key elements such as classes, objects, methods, and the advantages of OOP, including modularity, reusability, and security. Additionally, it covers class declaration, constructors, and principles like encapsulation, inheritance, and polymorphism.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Basic Object Oriented Programming Concept

The document provides an overview of Object-Oriented Programming (OOP) concepts, contrasting them with procedural programming. It explains key elements such as classes, objects, methods, and the advantages of OOP, including modularity, reusability, and security. Additionally, it covers class declaration, constructors, and principles like encapsulation, inheritance, and polymorphism.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 20

COS361 NOTE (PART 1)

1.0 Basic Object-Oriented Programming Concept

Writing programs in most of procedural programming languages such as BASIC, FORTRAN,


COBOL, PASCAL, ADA, etc requires the use of data structure, the design of algorithms and
converting of the algorithm to programs. This approach is completely different in the case of
object-oriented programming language like JAVA.

Object Oriented Programming (OOP) is a computer programming approach that gives


computational capabilities to objects during problem solving. Object Oriented Programming
involves the bundling of data and instructions into a variable called object and then give the
object messages to perform certain tasks or operations. In Object Oriented Programming, the
software design is organized around objects rather than functions and logic. An object is a part of
program that has the required information to perform certain actions in a program and also
interact with other elements of the program. It is referred as a data field that has unique attributes
and behaviour. An example of object could be a person, with name of the person as one of the
attributes or properties and walking as one of the behaviours of the person, otherwise known as
methods.

Attributes show the state of an object, and represent the characteristics, properties or state that
distinguish classes. The object of a class possesses the data stored in the attribute field or
variable of that class.

Methods on the other hand represent the functions that can be performed by objects. These
methods are defined inside classes and they describe the behaviours of the objects.

From the history of OOP, it was noted that the basis for OOP started in the early 1960s with
Simula 67 as the first programming language to use objects. Smalltalk, developed at the Learning
Research Group at Xerox's Palo Alto Research Center in the early 1970s was taken by many as
first pure object-oriented programming language. In 1982, C++ was implemented after C
programming language with the addition of classes. The design of C++ was done by Bjarne
Stroustrup by combining certain features of Simula with the C programming syntax. Later Java
programming language was modelled after C++ in 1991.

Advantages of Object-Oriented Programming

Modularity:

Modularity: Encapsulation enables objects to be self-contained, making


troubleshooting and collaborative development easier.

1
Reusability: Code can be reused through inheritance, meaning a team does not
have to write the same code multiple times.

Productivity: Programmers can construct new programs quickly through the use
of multiple libraries and reusable code.

Easily upgradable and scalable: Programmers can implement system


functionalities independently.

Interface descriptions: Descriptions of external systems are simple, due to


message-passing techniques that are used for object communication.

Security: Using encapsulation and abstraction, complex code is hidden,


software maintenance is easier and internet protocols are protected.

Flexibility: Polymorphism enables a single function to adapt to the class it is


placed in. Different objects can also pass through the same interface.

Code maintenance: Parts of a system can be updated and maintained without


embarking on very significant adjustments.

Lower cost: Benefits, such as easy maintenance and reusability minimizes


development costs.

Difference between Object Oriented Programming and Procedural Programming

Difference between Object Oriented Programming and Procedural Programming Procedural


Programming is given below.

Object Oriented Programming Procedural Programming

Object Oriented Programming a program is Program is created step by step instructional


created in a way as real-world object works format and instructions are executed in order

Uses bottom to top approach design Uses top-down approach

Provides effective means of simulating real- Does not have the means to simulate real-
world event world event effectively

Reduced development time Increased development time

2
Secure because it has proper way of data Less secure because it does not have any
hiding proper way of data hiding

Provide code reusability feature Does not provide code re-usability feature

In this chapter, we are going to look at the basic concepts of object-oriented programming which
include classes, objects, methods instance variables, class declaration, class creation,
constructors, access modifiers, inheritance, homomorphism and data abstraction. The object-
oriented programming approach arranges programs in a real-world object-like form such that
every object is associated with both properties and operations.

1.2 Classes and Objects


All program codes and data in java reside inside objects and classes, this is to say that all Java
programs are object oriented. A class is a template or a blueprint for an object while an object is
an instance of a class. A class consists of two major components, data elements or variables and
code elements contained within methods. A variable is said to be an instance variable when it has
class scope in its declaration. That is to say that the variable was not declared inside a class
method. The data element (field) with the value it holds represent the state of the object in a
program and its behaviour or operation is represented by set of methods that describes the type of
tasks the object performs.

Java classes may contain the main method which is the starting point of your program. The main
method is required to execute java program. There are Java classes that do not contain the main
method; such classes are not executable on their own.

For better understanding of these concepts, let us take a simple analogy of using a mobile phone
to make calls. If you want to make a call with your phone, you first press the phone number of
the recipient and press SEND or OK key of the phone. For this to work, the mobile phone will be
built first by the manufacturer. Now, to build the phone requires making an engineering drawing
of the phone description on paper just as house plan is first drawn by a civil engineer. The
engineering drawing on the paper in this analogy represent the class with the description of the
phone. The properties of the phone represent the variable of the class while the tasks that the
phone can perform represent the methods of the class. Since the engineering drawing on the
paper cannot be used to make call, the physical phone has to be constructed following the
specifications in the drawing before you can use it for making calls. This physical phone
constructed represents the object of the class. The alphanumeric keys “hides “the mechanism of
displaying characters on the screen, the OK or SEND key “hide” the mechanism of initiating call
connection to the recipient. This enables users with little or no idea of how phone works to use it
with ease. To make call, pressing the number keys send message to the phone to perform the task

3
of displaying recipient’s phone number on the screen of the phone. Also, pressing the OK or
SEND key sends message to the phone to perform the task of initiating a call. This is the same
way we send message to object of a class through method call and tell the method of the object
to perform a task. The method is the task that is performed when the key is pressed and the
variables are attributes such as the colour, size, shape and different parts of the phone.

Class declaration and creation, Access Modifiers and Constructors


Classes Declaration
Every Java program must consist of at least one class that you (programmer) defined, otherwise
called user-defined classes of programmer-defined classes. There are classes used by
programmer in developing Java Programs which were not defined by them, such classes are
inbuilt in the java libraries housed by the Java Development Kit (JDK). These categories of Java
classes are imported before they can be used and the importation is done using import statement.

We have said that class is a template of an object, therefore, in class declaration; all the features
that object of that class will possess are specified within the class. Every class that starts with
keyword puplic must be stored in a file that has the same name as the class with .java file-name
extension. We will use an example to illustrate how class is declared. Apart from public key
word, class can be specified using other key words like abstract or final or without any modifier
or specifier. . Here is an example of the class for a triangle.

public class Triangle


{
// the properties of the triangle representing instance variables
double base = 2.0;
double height = 4.0;

// the behaviour of triangle representing method


public double findArea()
{
return 0.5 * base * height;
}
}

This class declaration begins with keyword public which is an access modifier. We will look at
access modifier in more detail in this section. The access modifier is followed with the keyword
class and then followed by the class’s name. The body of the class is placed within a pair of open
and close braces. The class we declared has two instance variables base and height, both are of
type double and one method with name findArea. The method is declared public indicating that
the method has public access, and has return type double. The open and close bracket that comes
immediately after the method’s name is what shows that it is a method that was declared. Since

4
there is no parameter defined within the open and close bracket, the method is referred to non-
argument method. The body of the method is also delimited in a pair of left and right braces. The
body of the method contains one or more statements that perform the task of the method. In our
example, we have only one statement, return 0.5 * base * height; which returns the area of the
triangle.

Class Triangle

base

height

findArea()

Fig.1.1 Declaration of Triangle class

Fifure 1.1 shows diagrammatical description of the Triangle class that was declared above.

Inner Classes or Nested Classes

With the release of JDK1.1 inner classes features were added. Inner classes are classes declared
inside other classes and as a component of a class can have any accessibility. The scope of inner
class can even be private. You will learn more about class accessibility under access modifier in
this chapter later. The inner class in our example below is called nested and has method
nestedMethod() and data element u. The full name of the nested class is outer.nested. The nested
class has a hidden reference to the outer class instance called this.

public class Outer


{
private int v;
// the following class is the nested class
Public class Nested
{
private int u;
//this is the nested class method
public void nestedMethod(){}
}
//this the outer class method
public void outerMethod(){}
}
To call the nested class from a static method requires an instance of the outer class. The
following code below can be added to the above code to have a complete example. Within a

5
static method such as the main method, there is no reference to the outer class; hence you must
take special efforts using the new operator and the instance of the outer class.

Public static void main(String args[]){


Outer.Nested n = new Outer().new Nested():
n.nestedMethod();
// the above can also be written this way
Outer o = new Outer():
Outer.Nested n = new Nested();
n.nestedMethod()
}

The Nested class can also be marked static. The keyword static means that the nested class is
associated with the outer class, instead of any particular instance of the outer class. Java allows
programmers to create class within method. It is also possible in Java to create an anonymous
class, which is a class without a specified name.

Anonymous Classes
Anonymous classes are classes created or declared within a method that do not have names. It
removes the burden of thinking of the names to give classes. The objects of such classes cannot
be created or instantiated any other place except where they were declared. The only way you
can instantiate such classes is by using new keyword followed by interface name. An anonymous
class should be made small, if it has more than two methods, it should probably not be declared
anonymous. Anonymous class does not have constructor since it has no specified name to
specify the constructor.

Objects

Objects are creations of classes or instances of classes. All the components of a class (variable
and methods) can only be driven when the object of the class is created. The object is used to
reference or invoke the class elements in order to perform those tasks specified by the class. The
way Java references the class elements is by first creating the object and using the object variable
to reference a particular element of the class.

Object creation

We use class to create object of that class type. However, a two-step process is involved in
creating object of that class type. Initially, you declare a variable of that object which just refers
to the object but does not define it. Thereafter, we obtain the physical copy of the object using
new operator (keyword), followed by the class-name with open and close bracket (default
constructor) and assign it to the variable using an assignment operator (=). These steps can be
performed by the line of code written below.

6
Triangle myTriangle = new Triangle(); This is line of code create a copy of the object of the
triangle class as shown in figure 1.2

Here, myTriangle is the object variable and it is of type Triangle.

Upon the invocation of the new operator, a triangle with the initial values of the base and height
as assigned in the triangle class is created. The object variable could be used to call the findArea
method of the class to return the area of the triangle created. For example:

myTriangle.findArea(); returns the area of the triangle. That is object variable followed by a dot
seperator (.) and the element name.

Class Triangle Object

base

height

findArea()

Fig.1.2 creating object of Triangle class

Assigning Object Reference Variable

Triangle t = myTriangle;

Assigning myTriangle to t means that both are referring to the same object and any change made
to the object through t affects the object myTriangle is referring. Even though t and myTriangle
are referring to the same object, they are not linked in any other way. This implies that a
subsequent assignment to t unhook t from the original object without affecting either the object
or myTriangle.

Methods

One of the major constituents of a class is method. Method manipulates the class member
variable. This means that method is declared first inside the class if it is not a method in an
existing java class in the library. Method declaration begins with the method header, followed by
left brace, body of the method and right brace. The general form of a method is as shown below.

Modifier ReturnType methodName (parameter-list)

7
// body of the method

Return value;

ReturType here specifies the type of data returned which include any of the valid data type.
When a method does not return data, its return type is said to be void. Parameter list is sequence
of type and identifier pair separated by commas. If the method has no parameter, then the
parameter list will be empty. Method that has a return type other than void return a value to the
calling routine as depicted above.

Overloading and Overriding

Method overloading occurs when the same method name with different arguments and perhaps
different return type. Imagine a method that calculates the area of a triangle, one such method
may take three of triangle’s sides while another may take three angles of the triangle a length of
one side. In a language that does not support overloading, you would think of having different
method names for a method performing a single action. So, in method overloading, you have a
method that has the same name and return type but the argument list differs either in the order or
type. It is true that overloaded method returns the same result since it performs a single action
with different elements. However, they may also return different result sets in line with their
arguments. Example:

public class Overload

// overloaded method examples

public void load ();{}


public void load (String s){}

public void load (String s, int i) {}

public void load (int i, String s) {}

Constructors

Constructors are type of methods that initializes an object immediately upon creation. It is
immediately called once created using the new operator. Constructors have the same name as
that of the class in which they were created inside it. They are different from methods with no
return type, constructors implicitly return the class itself. Finalizers are methods called prior to
garbage collection.

8
Type of Constructor

We have default and overloaded constructors.

Default constructor takes no arguments and is created by the complier if no other constructors
are defined in the class. It has public accessibility.

Overloaded constructor takes arguments and is explicitly defined in that class. Example is shown
below:

Public class Myclass

double a;

int b;

public Myclass(){

// this is default constructor

Public MyClass(double a, int b){

//this overloaded constructor

Constructors are not inherited into subclasses. You must define each form of constructor that you
need because the component of each class has to be initialized separately. A constructor can
however call the base class constructor using super() mechanism.

Principles of Object-Oriented Programming Languages

Object Oriented Programming languages support at least any of these three principles:
Encapsulation, Inheritance and Polymorphism.

Abstraction
Abstraction is an object-oriented programming principle that allows the showing of important
functionalities to user and the hiding of unwanted information. The unique characteristics of
abstraction is the hiding of unnecessary implementation details from the users. Abstraction
focuses on how to use it and not how it does it.
9
Public class Details
{
Private string name
Private string address
Public void showdetails (string myName, myAddress)
{
name = myName;
address = myAddress;
System.out.println (“the details are +name + “from” + address”);

Int main()
{Detail = new detail(John, No4 Eze Street, Nsukka )
}
}
}
In this example, the variable, name and address are private and as such are not accessible to any
code apart from class detail

Encapsulation
Encapsulation is a concept of object-oriented languages that support the idea of bundling data
and instructions into a variable called an object thereby providing access control to the
information against the outside world. Encapsulation, also called protective wrapper binds both
data and the codes that manipulates them together and at the same time keeps both safe from
outside misuse and interference. A well-defined interface is used for strict control of access to
the bound codes and data. The basis of encapsulation in Java is the class, since when you create a
class; you will specify the code and data that constitute that class. Collectively, these class
elements are called members of the class. Specifically, we refer to data defined by the class as
member variables or instance variables while the codes that manipulate those data are called
member method or just method.

Inheritance

The principle of inheritance provides the ability to enhance or extend the existing objects.
Inheritance is a concept which creates a general class that defines traits common to a set of
related classes and allowing each specific classes to inherit the properties of the general class,
each adding item unique to it. To inherit a class, you simply incorporate the definition of the
superclass (base class) into the derived class (subclass) using extends keyword. Sometimes,
superclass is also called parent class and subclass called child class. Through inheritance, the
object of one class can acquires the properties of the object of another class. This concept of

10
inheritance provides the idea of reusability, which means that additional features can be added to
an existing class without modifying it. The super keyword refers to the superclass of the class in
which super appears. It can be used to invoke the superclass constructor of the superclass
method. The code below illustrates inheritance.

// creating a supper class

Class Top{

private int x;

public int y;

public void showTop(){

//Body of the method

// Creating the sub class

Public class Bottom extends Top{

public int j;

public void showBottom(){

//Body of the method

Even though the derived Bottom has been inherited from the base class Top, it is completely
independent and stand-alone class. Moreover, a sub class can also be the base class to other
classes. It is pertinent to note that Java does not support multiple inheritance. This means that a
single class cannot inherit from more than one base or supper class, rather Java supports only
multi-level inheritance. The problem of multiple inheritance is however solved using interface.

Polymorphism

Polymorphism is an object-oriented programming concept that allows the processing of objects


that share the same super class as if they are all objects of the super class. It is the ability to take
more than one form, that is, the same message sent to variety of objects producing many forms
of result. Polymorphism is very vital in processing objects that have different internal structure

11
but are to share the same external interface. The concept of polymorphism is often expressed by
the phrase “one interface, multiple methods”. With polymorphism, we can design and implement
a general class of operations that may be accessed in the same manner even though the specific
actions associated with each operation may differ. Polymorphism is used in implementing
inheritance. Let’s consider an example of polymorphism implementation.

Class Shape{

// method for drawing shape

Public void draw(){

System.out.println(“drawing shape ……”);

Class Triangle extends Shape{

// method for drawing triangle

Public void draw(){

System.out.println(“drawing triangle ……”);

Class Rectangle extends Shape{

// method for drawing rectangle

Public void draw(){

System.out.println(“drawing rectangle ……”);

Class main{

Public void main(String args[]){

//create object of triangle

Shape t = new Triangle ();

12
t.draw();

//create object of rectangle

Shape r = new Rectangle ();

r.draw();

The above example can also be modified as follows:

Class Shape{

// method for drawing shape

Public void draw(){

System.out.println(“drawing shape ……”);

Class Triangle extends Shape{

// method for drawing triangle

Public void draw(){

System.out.println(“drawing triangle ……”);

Class Rectangle extends Shape{

// method for drawing rectangle

Public void draw(){

System.out.println(“drawing rectangle ……”);

13
Class main{

Public void main(String args[]){

//create object of triangle

Triangle t = new Triangle ();

t.draw();

//create object of rectangle

Rectangle r = new Rectangle ();

r.draw();

Programming Control Concepts


Control concepts refer to those programming techniques that programmers use to determine
statements of a program are being executed. Apart from sequential execution of statements, the
execution of statements of a program can be controlled through the use of selective and repetitive
control concepts.

Selective Control Concepts

In Java, there are three selective control statements or concepts or structure that programmer can
use in writing structured programmers. The selection statement has a boolean expression that
either evaluates as true or false and the result of the evaluation determines the actions to be
performed. Here, we are going to learn about the three types of selection statement available in
Java
If Single-Selection Statement
The if single-selection statement executes an action only when the Boolean expression evaluate
as true and skips execution when the boolean expression evaluates as false. This selection
statement is called If single-selection statement because it selects or skips a single action
depending on the outcome of the of the evaluation of the given boolean expression.

 The Syntax of if single-selection statement


The syntax or format for the If single-selection statement is as follows:

14
If (booleanExpression)
{
Statement(s);
}

From what we have above, if the booleanEpression evaluates as true, the statement or statements
in the block are executed; and skipped, if the booleanEpression evaluate as false.

If...Else Double-Selection Statement


As earlier stated, if single-selection statement executes one single block of action, if the
condition is true; and the block of action is skipped, if the condition is false. However, if…else
double-selection statement allows the specification of action to be performed when the
booleanExpression evaluates as true and a different action to be performed when the
booeanExpression evaluates as false. Therefore, the actions which if…else double-selection
statement takes differ based on whether the condition is true or false.
 The syntax of if..else double-selection statement
Below is the syntax for if…else double selection statement.
If (booleanExpression)
{
Ststement(s); //statements executed when condition is true
}
Else
{
Statement (s); // statements executed when conditions is false.
}

From the above syntax, the statements within the if block are executed, if the boolean expression
evaluates to true, otherwise, the statements within the else block are executed.

Nested If Statement
If statements or if…else statement can be placed inside another if statement or if…else
statement. When this is done, the inner if statement or if…else statement is said to be nested in
15
the outer one. The inner if statement contain another if statement or if…else statement and this
can occur to any limit. For instance, the following code snippet illustrates nested if statement:
if (j > 0)
{
if (k<0)
cout << “ k is a negative number and j is a positive number’’;
}
cout << “ j may be zero or negative number’’;

Since there is no limit to nesting of if statement, the nested if statement can be used to implement
multiple alternatives.

 Syntax of a simple nested if statement


The syntax for a simple nested if statement is show below
If (booleanExpression)
{
If (blooleanExpression)
{
Statement(s);
}
}

diagram

Switch Statement
Java provides the switch multiple-selection statement to perform different actions based on the
possible values or expression or integer variable. Each action has a value or a constant integral
expression associated to it. When nested if statement is over used, it make program difficult to
read and to understand. But with switch statement, multiple conditions are efficiently handled.
The switchExpression must yield a value of char, byte, short or int type and must be enclosed in
a bracket.
 Syntax for the switch statement
16
Below is the syntax for the switch statement:
switch (switchExpression)

case value1: statements1;

case value2: statements2;

break;

case valueN: statementsN;

break;

default: statements for default;

The value1…valueN must have the same data type as the value of the switchExpression. The
statements whose case value matches the value of the switch Expression are executed. Once
executed, the execution of the break statement follows which takes control out of the switch
block. If none of the case value matches the value of the switchExpression, the statements for
default are executed.

Repetitive concept
Repetitive concept or structure also referred to as loop or iteration structure is a structured
programming concept that allows a programmer to specify that a program should repeat an
action as long as some condition remains true. It can also be said that loops are structures that
control repeated executions of block of statements. Java provides three types of repetitive
statements namely; while repetitive statement, do- while repetitive statement, and for repetitive
statement.

While Repetitive Statement


While repetitive statement or loop allows repeated execution of actions as long as a condition
remains true. Every repetitive statement contains a loop-continuation condition, which is a

17
booleanExpression that controls the actions performed within the loop body. At the end of every
iteration, the loopContinuationCondition is reevaluated. If the result of the reevaluation remains
true, the body of the loop is repeated, otherwise the loop terminates. The syntax for the while
repetitive statement is as follows;

 while ( loopContinuationcondition)
 {
 Statement(s);
 }

 The part of the loop that contains the statements to be executed is referred to as the loop
body and it is enclosed in curly braces. The curly brace is not compulsory, if the loop
body contains only one statement. The loopContinuationCondition which is a boolean
expression must be enclosed in parenthesis and it is evaluated before the loop body is
executed. Once the condition is no longer true, the loop terminates and program control
transferred to the next statement after the loop.

Do-while Repetitive Statement


The do-while repetitive statement is a variation of while repetitive statement. The while
repetitive statement evaluates the loop continuation condition before executing the loop body, if
the condition is false, the loop will not execute at all. On the other hand, the do-while repetitive
statement executes the loop body before the condition is evaluated. Therefore, in do-while loop,
the loop body must be executed at least once before termination. When the do-while loop
terminates program control is transferred to the next statement following the do-while loop. The
syntax for the do-while repetitive statement is as follows;

 do
 {
 Statement(s);
 } while ( loopcontinuationcondition);

18
You should remember to enclose the condition in paratheses and terminate it with semicolon;
otherwise error will be triggered during compilation. As it can be seen above, the do-while
repetitive statement executes the loop body first before checking the
loopContinuationCondition to determine whether to continue or not. An example of how do-
while repetitive statement can be used in a program is shown in the program snippet below:
 do
 {
 J = 1;
 cout<< j;
 j = j+1;
 } while (j <= 10);

 This code also prints numbers 1 to 10 as long as the condition remains true. The only
different between this code and the one shown on while repetitive statement is that the
number 1 must be printed whether the condition is true or false. This is not the same with
while repetitive because if the initial test fails, no single number will be printed.

For Repetitive Statement


The repetitive structure called for repetitive statement is used to perform an action for a known
number of tomes. It specifies the counter-controlled-repetitive details in a line of code. The
general syntax of for loop is shown below:
 for ( initial Action; loopContinuationCondition; actionAfterEachIteration)
 {
 Statement(s);
 }

The for loop statement begins with the keyword for, followed by initial Action,
loopContinuationCondition, and actionAfterEachIteratinon , all enclose in parentheses, then a
loop body (statements to be executed), which is inside curly braces. The initialAction,
loopContinuationCondition and actionAfterEachIteration which are inside a parenthesis are
separated by semicolons. The for loop uses variable called control variable to control the number

19
of times the loop body is executed. The initial Action initializes the control variable, the
actionAfterEachIteration increments or decrements the control variable, while the
loopContinuationConditin checks whether the control variable has gotten to the final value
(termination value). Example below illustrates how you can use for repetitive statement
 For (int k = 0; k < 10; k++)
 {
 Cout<< “1 am in Java programming class’’;
 }

The initialAction (int k = 0) declared and initialized the control variables, k. the control
variable can also be declared outside for loop but it initialization must take place inside the
parenthesis.
The loopContinuationCoddition (K<10) is a booleanExpression and it is evaluated at the
beginning of each iteration. The loop body continues to each time the condition evaluates as true
but terminates and transfers program control to the statement after the loop. The
actionAfterEachIteration (k++) which is the same as k =+ 1 increments the control variable and
forces the loopContinuationCondition to false. If the loop body contains a single statement, the
curly braces can be omitted. You should avoid putting semicolon after for clause to eliminate the
error that goes with such. Hence, the program snippet above will continue to print “I am in
computer programming class” until the loopContinuationCoddition is evaluated to be false.

20

You might also like