POO Flashcards
Characteristics of Object
Abstraction
Encapsulation
Message passing
What is abstraction ?
Abstraction: Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user
What is encapsulation ?
Encapsulation: Encapsulation simply means binding object state(fields) and behaviour(methods) together. If you are creating class, you are doing encapsulation.
What is Message passing ?
A single object by itself may not be very useful. An application contains many objects. One object interacts with another object by invoking methods on that object. It is also referred to as Method Invocation.
Object Oriented Programming features
Abstraction , Encapsulation ,Inheritance ,Polymorphism
So what is the benefit of encapsulation in java programming
Well, at some point of time, if you want to change the implementation details of the class EmployeeCount, you can freely do so without affecting the classes that are using it.
Inheritance
The process by which one class acquires the properties and functionalities of another class is called inheritance. Inheritance provides the idea of reusability of code and each sub class defines only those features that are unique to it, rest of the features can be inherited from the parent class. The biggest advantage of Inheritance is that the code in base class need not be rewritten in the child class. Multi-level inheritance is allowed in Java but not multiple inheritance
Polymorphism
Polymorphism is a object oriented programming feature that allows us to perform a single action in different ways
Types of Polymorphism
Static and dynamic
Static Polymorphism
Polymorphism that is resolved during compiler time is known as static polymorphism. Method overloading can be considered as static polymorphism example.
Method Overloading
Method Overloading: This allows us to have more than one methods with same name in a class that differs in signature.
Dynamic Polymorphism
It is also known as Dynamic Method Dispatch. Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime rather, thats why it is called runtime polymorphism. Since both the classes, child class and parent class have the same method animalSound. Which of the method will be called is determined at runtime by JVM.
Abstract Class and methods in OOPs Concepts
Abstract method:
1) A method that is declared but not defined. Only method signature no body.
2) Declared using the abstract keyword
Used to put some kind of compulsion on the class who inherits the class has abstract methods. The class that inherits must provide the implementation of all the abstract methods of parent class else declare the subclass as abstract.
6) These cannot be abstract
Constructors
Static methods
Private methods
Methods that are declared “final”
Characteristics of Abstract
Note 2: Abstract class cannot be instantiated which means you cannot create the object of abstract class. To use this class, you need to create another class that extends this abstract class provides the implementation of abstract methods, then you can use the object of that child class to call non-abstract parent class methods as well as implemented methods(those that were abstract in parent but implemented in child class).
Note 3: If a child does not implement all the abstract methods of parent class(the abstract class), then the child class must need to be declared abstract.
Interfaces in Java
An interface is a blueprint of a class, which can be declared by using interface keyword. Interfaces can contain only constants and abstract methods (methods with only signatures no body).Like abstract classes, Interfaces cannot be instantiated, they can only be implemented by classes or extended by other interfaces. Interface is a common way to achieve full abstraction in Java.