2. OOP is a programming paradigm
What is programming paradigm
A method or way to write a computer program for real world applications.
Is there any other programming paradigm exists
Yes
Which one?
Structure programming
Functional programming
Procedural programming
Logical programming
4. Classes
Objects & methods
Inheritance
Polymorphism
Abstraction
Encapsulation
Mastering these concepts means you are going to become an expert programmer in
industry soon.
5. To understand OOP concepts relate them with real world.
Whatever you do in your real world is actually one of the OOP concept.
6. Smalltalk is first and purely OOP language.
JAVA, C#, C++, Python etc these all are OOP languages.
7. In real world class means a presentation for the group of some related objects like
Animals class
Birds class
Vehicles class
Human class, etc.
For example if we talk about animal class than which objects should fall in this class
Dog
Cat
Horse
Tiger, etc.
8. For example in bird class objects should be
Sparrow
Peacock
Parrot
Owl, etc.
A class represents some methods/activities that the objects of that class follow, for
example
Animals can (eat, run, walk, drink, fight, etc)
Birds can (fly, eat, walk, drink, etc)
Humans can (eat, run, walk, drink, fight, read, etc)
9. Class is the collection of objects.
Class is not the real world entity, it is just the template or blueprint.*
Class does not occupy memory.**
10. access-modifiers class ClassName
{
Class body (methods, constructors, fields, blocks, nested class);
}
In case of no access-modifier will written the default access modifier will be
considered.
11. Method is a set of code which perform a particular task.
Example eat(), run(), walk(), etc.
Advantages of methods:
Code reusability
Code Optimization
12. access-modifier return-type methodName (list of parameters)
{
Method body(conditional, switch, control statements, variables etc)
}
If no access-modifier place the default modifier will take place in java.
13. Object is an instance of class e.g. dog is an instance of animal.
Object is real world entity.
Object occupies memory.
14. Identity: name
State/Attribute: Breed, Age, Color
Behaviors: Eat(), Run(), Bark()
15. There are five ways to create object in java
By using new keywords
By using newInstance() method
By using clone() method
By using deserialization
Mainly objects created by using new keyword.
16. Declaration
Declare variable that represent the object name. For example
Animal buzo;
Instantiation and Initialization (Initialization perform by using class name constructor.
)
buzo = new Animal();
By combining declaration, instantiation and initialization the object can be create using
following syntax.
Animal buzo = new Animal();
17. The behavior/method of object call by using dot (.) operator.
For example
buzo.run()
buzo.eat()
How to change the state/attribute of an object?
The state/attribute of object can also be change by using dot(.) operator.
For example
buzo.color = black;
buzo.age=3;
18. public class Animal
{
Int age = 1;
String breed = “GS”;
public void eat()
{
System.out.println(“I am eating”);
}
public void run()
{
System.out.println(“I am running”);
}
}
public static void main (String args[])
{
Animal dog = new Animal();
System.out.println(dog.age);
System.out.println(dog.breed);
dog.run();
dog.eat();
}
Editor's Notes
*(if I want to see the animals I will see the objects, word animal is nothing but representation of a group of objects)
**because only real entities occupy space in real world.
*Four access modifiers in java
Default
Public
Private
protected