Chapter - 1 Introduction To Object-Oriented Programming
Chapter - 1 Introduction To Object-Oriented Programming
Chapter - 1 Introduction To Object-Oriented Programming
Bedasa Wayessa
[email protected]
Compiled by Bedasa OOP- CoSc2051 1
Classroom Rules
• Late comer will only tolerated for the first 5 minutes of every class
• Talk to me and Not to each other
• Do not sleep
• Do not use phones
• Fail to obey the Classroom rule face 2 3 class ban
Assessment method
Task Task Type Session Max Mark
1 Test Lab & Theory Individual 30
2 Assignments/Quiz Lab & Theory Individual 10
3 Project Lab Individual/group 10
4 Final Exam both Individual 50
Total 100
Functional Logic
Programming Programming
Algol Lisp Prolog Smalltalk
Cobol Haskell Simula
PL/1 ML C++ , C#
Ada Miranda Java ,VB
Fortran APL
C
Modula-3
System.out.println(sum); // Output: 15
}
}
import java.util.Arrays; is necessary to use the Arrays class.
An array of integers is defined: int[] numbers = {1, 2, 3, 4, 5};.
The Arrays.stream(numbers) method converts the array into a
stream, which allows you to perform operations on it.
base class /
derived class inherits parent class
Base class
. Person
+Name: String
+Address: String
Employee Student
+Company: String +School: String
+Salary: double
Person
-name : String
-age : TimeSpan
+Person (String name, int age)
+Name : String { get; set; }
+Age : TimeSpan { get; set; }
Figure Abstract
. action
+CalcSurface() : double
Concrete
class Square Circle
-x : int -x : int
-y : int -y : int
Overriden -size : int -radius: int Overriden
action action
// Instance variable
int instanceVar;
// Local variable
int localVar = 5;
if (CONDITION) {
// Statements to be executed if the condition is true
}
int x = 10;
if (x > 5) {
System.out.println("x is greater than 5");
}
• In this example, if the condition x > 5 is true, the statement inside the
curly braces will be executed, and "x is greater than 5" will be printed to
the console.
Compiled by Bedasa OOP- CoSc2051 79
Control Structures
• Conditional Branches: if else
• The else statement is used to execute a block of code if the same
condition from the if statement is false.
• The syntax for the if statement is as follows:
int y = 3;
if (y > 5) {
System.out.println("y is greater than 5");
} else {
System.out.println("y is not greater than 5");
}
• In this case, if y > 5 is false, the statements inside the else block will be
executed.
• Remember that the condition in the if statement should be a boolean
expression, which means it evaluates to either true or false.
Compiled by Bedasa OOP- CoSc2051 80
Control Structures
• Conditional Branches: if else if
• In Java, the combination of if and else if statements is used when you
have multiple conditions to check, and you want to execute different
blocks of code based on the evaluation of these conditions.
• The if-else if structure allows you to create a series of conditions, and
the first one that evaluates to true will have its corresponding block of
code executed.
• Each fi or else if block contains a condition.
• If the condition in the if block is true, the statements within that block
will be executed, and the subsequent else if and else blocks will be
skipped.
switch (expression) {
case value1:
// Code to execute if expression matches value1
break;
// More cases...
default:
// Code to execute if no case matches
}
default:
System.out.println("Invalid day");
}