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

Object Oriented Programming

Uploaded by

xeye4974
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Object Oriented Programming

Uploaded by

xeye4974
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

104.

Principle of Object-
Oriented Programming.
1. Learning OOP is different than learning java.
2. OOP’s concept are important.
3. Concept’s:
a. Abstraction:
b. Encapsulation:
c. Inheritance:
d. Polymorphism:
4. Abstraction:
a. Hiding internal details and showing required
features.
b. See only required things.
5. Encapsulation:
a. Binding everything inside a single container.
6. Inheritance:
a. Inheriting the properties/features from previous
things into current one
b. Same as specialization.
7. Polymorphism:
a. It is same generalization.

8. Specialization: Adding newer feature in current thing


and making new thing out of it is called specialization.
9. Generalization: Grouping similar things under one
name.
10. Think them in terms of real-world life things.

105. Class vs Object


1. Anything in the world is called an object.
2. Anything in world can defined in terms of properties and
behaviour.
3. Object: Object is defined in terms of its properties and
behaviour.
4. Behaviour will affect, utilise the properties.
5. Simple method to identify the properties and methods of
object:
a. Write everything about it.
b. Nouns and adjectives are properties.
c. Verbs are behaviours.
6. Class is a blueprint. Object is an instance of the class.
7. Class is logical and Object is real.
8. We can create as many object as we want from class.
9.
a. Objects are created in the heap.
b. Variables (reference variable) occupy memory of
stack.
c. Methods will be in method area.
10.

106. How to write the classes.


1. Circle:
a. Properties:
radius.
b. Methods:
area.
perimeter.
2. Rectangle:
a. Properties:
length.
breadth.
b. Methods:
area.
perimeter.
3. Cylinder:
a. Properties:
radius.
height.
b. Methods:
area.
volume.
4. Student:
properties:
roll number.
name.
course.
marks.
methods:
total marks.
result.
grades.
percentage.
5. account:
properties:
account number:
methods:

107. Writing a Class for Circle.


1. We should define methods and properties.
2. We should define datatypes of circle.
3. We should define parameters required by methods and
return type of method.
4. There is a built-in constant give in java inside class Math
which is pi.
Math.PI
5. Every class java will create a separate file.

108. Student Challenge: Write a


Class for Rectangle.
109. Student Challenge: Write a
Class for Cylinder
110. Student Challenge: Write a
Class for Student.
1. To print the class directly with reference it should have
toString() method.
For example
Student s = new Student();
System.out.println(s);

111: Data Hiding.


1. Data hiding makes the using object simple.
2. It prevents the user from hindering with inside
mechanism.
3. To hide we use access modifiers:
a. private: We cannot access outside the class.
b. public: We can access anywhere.
c. protected: We can access it inside the class and
inside the child classes.
4. The getter and setter method is used get and set the
variables. They helps to prevent from getting data
mishandled. They can also do job of setting the data.

112. Practicing Data Hiding.


1. It is good to keep sensitive class variables private.

113. Type of Properties.


1. Type of Properties:
a. Read and Writable
b. Read Only.
c. Write Only.
2. class Student
a. Read and Writable: Marks. (most properties.)
b. Read Only: Name of the student.
c. Write Only: depositing money in account. ( Required
in between two threads, class (Most rare situation))

114. Constructor
1. Constructor: It is a method of class which is called
automatically upon creation of object.
2. Every class in java have default constructor.
3. Constructor doesn’t have any return type.
4. Usually, we make constructors public.
5. Constructors have same name as class.
6. There are two types of constructor:
a. Default constructor.
b. Parameterized constructor.
7. Constructor is used to initialize values.

115. Practicing Constructors.


1. Methods starting with word “is” are called as enquiry
methods.
2. Methods of class called as instance methods or
facilitators.

116. Student Challenge: Cylinder.

117. Student Challenge: Product


and Customer.
Product:
a. itemno
b. price
c. qty
d. name
1. set methods to modify.
2. constructor is for setting the values.
3.
Customer
a. customer no
b. name
c. address
d. phone

1. Decide appropriate datatype.

118. Array of Objects Challenge.


1. “this”: It is a key word used as a reference to current
object.

You might also like