A class is therefore set of attributes put together in one container or capsule. This process of putting together attributes and methods (behavior) is called Encapsulation.
CSI21M1 Java Programming Notes, prepared by Mr. S. Nyika, Semester I, 2019
Lecture 1: Object Oriented Programming
Objectives:
At the end of this lecture, students will be able to:
• explain the important principles of Object Oriented Programming
• define the term class
• define the term object
• explain the relationship between a class and its objects
• understand that there are two kinds of programmers
• explain why class programmers need to hide data
• advantages of Object Oriented Programming as opposed to linear programming
• Write a class in java syntax
Notes:
A class in Java is the same as a class in C++. It has attributes and behaviour which are put together as
one unit. This unit is called a class. A class is therefore set of attributes put together in one container or
capsule. This process of putting together attributes and methods (behaviour) is called Encapsulation.
An example is the car. When this is taken as a class will therefore appear with attributes and methods or
functions. There are three principles which are used to make sure the class is well formed. These are
Encapsulation, Polymorphism and Inheritance. Encapsulation is the bundling together the attributes
and the methods as follows:
class Car
{
String carModel;
int engineNumber;
int yearManufatured;
void setCarModel(String model)
{
carModel=mode;
}
void setEngineNumber(int enumber)
{
engineNumber=enumber;
}
void setYearManufactured(int year)
{
yearManufatured=year;
}
String getCarModel()
{
return carModel;
}
int getEngineNumber()
{
return engineNumber;
}
int getYearManufactured()
{
return yearManufatured;
}
}
Page 1 of 4
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller keanuperumal. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $2.82. You're not tied to anything after your purchase.