CSC 305 Slides 2
CSC 305 Slides 2
4 provides data hiding and inheritance does not have proper way of hiding data so it
is less secure
1. Encapsulation
Encapsulation refers to the bundling of data (attributes) and the methods (functions or
procedures) that operate on that data into a single unit known as an "object." The
object acts as a self-contained entity, and the internal details of its implementation are
hidden from the outside world. This promotes information hiding and reduces
complexity.
2. Abstraction
Abstraction involves simplifying complex systems by modeling classes based on the
essential properties and behaviors they share. It focuses on what an object does rather
than how it achieves its functionality. Abstraction allows programmers to create a high-
level model that hides the implementation details and emphasizes the essential
features of an object.
Principles of Object Oriented Programming (Cont’d)
3. Polymorphism
Polymorphism allows objects of different types to be treated as objects of a common
type. It enables a single interface to represent different types of objects, providing
flexibility and extensibility. There are two types of polymorphism: compile-time
(method overloading) and runtime (method overriding).
4. Inheritance
Inheritance is a mechanism that allows a new class (subclass or derived class) to inherit
the properties and behaviors of an existing class (superclass or base class). This
promotes code reuse and the creation of a hierarchy of classes, where common
functionalities are shared among related classes. Types of inheritance include; single
inheritance, hierarchical inheritance, and multilevel inheritance
Principles of Object Oriented Programming (Cont’d)
Single Inheritance Hierarchical Inheritance
One child class is derived from one base class. Multiple child class can be derived from one base class.
Principles of Object Oriented Programming (Cont’d)
Multilevel Inheritance
Here, the parent class has a grandchild
Java
Java Character Set
Java character set implies that the set of characteristics, symbols, notations applicable to Java
e.g. Digit -0-9
Alphabet –A-Z (upper & lower case)
Arithmetic Expression symbols =+, -, *, / e.t.c.
Special characters =, ^, *, % e.t.c.
Not Equal !=
I/O Statements in JAVA
We have (3) class declaration in JAVA
(i) Public (ii) Private (iii) Protected
PUBLIC:
In public, the program is visible to all members of the class and other external classes
PRIVATE:
In private, the program is only visible to the member of that class and to friend classes.
PROTECTED:
Here the program is visible to the members of that class, friend classes and desired classes
(ii) println: The println method is used to print the specified content to the console and then move the cursor to the next
line. It automatically appends a newline character (\n) at the end.
System.out.println("Hello, ");
System.out.println("world!");
Displays: Hello,
world!
(iii) printf: The printf method is used for formatted output. It allows you to specify a format string with placeholders.
String name = "John";
int age = 25;
System.out.printf("Name: %s, Age: %d", name, age);
Example:
EXAMPLES
Write a program for 90 students in which the 1st 25 student’s numbers will only be
generated