Object-Oriented Programming Fundamentals Flashcards
What are the fundamental principles of object oriented programming?
a) Inheritance
b) Abstraction
c) Polymorphism
d) Encapsulation
Inheritance in Java
Inheritance in java is used to add additional functionalities to the existing class. Inheritance is used to extend the present class by adding some more properties to it. Inheritance is used to reuse the present tried and tested code so that you may not have to write them and compile them again.
Types of inheritance in Java:
1) Single Inheritance : One class is extended by only one class.
2) Multilevel Inheritance : One class is extended by a class and that class is extended by another class thus forming chain of inheritance.
3) Hierarchical Inheritance : One class is extended by many class.
4) Hybrid Inheritance : It is a combination of above types of inheritance.
There exist one more type of inheritance – Multiple Inheritance.
5) Multiple Inheritance : One class extends more than one class.
But, Multiple Inheritance is not supported in java. To avoid the ambiguity, complexity and confusion, multiple inheritance is not supported in java.
https://javaconceptoftheday.com/inheritance-in-java/
Abstraction in Java
Abstraction is used to separate ideas from their implementation. Abstraction in java is used to define only ideas in one class so that the idea can be implemented by its sub classes according to their requirements. For example,
abstract class Animal { abstract void soundOfAnimal(); // It is just an idea }
class Cat extends Animal { void soundOfAnimal() { System.out.println("Meoh"); //Implementation of the idea according to requirements of sub class } }
class Dog extends Animal { void soundOfAnimal() { System.out.println("Bow Bow"); //Implementation of the idea according to requirements of sub class } } Abstraction in java is implemented using Abstract classes and interfaces.
https://javaconceptoftheday.com/abstraction-in-java/
Polymorphism in Java
Polymorphism in java refers to any entity whether it is an operator or a constructor or any method which takes many forms or can be used for multiple tasks either while compiling or while running a java program.
There are two types of polymorphism in Java.
1) Static Polymorphism
Any entity which shows polymorphism during compile time is called static polymorphism. Operator Overloading, Constructor Overloading and method overloading are best examples of static polymorphism. Because, they show polymorphism during compilation.
2) Dynamic Polymorphism
Any entity which shows polymorphism during run time is called dynamic polymorphism. Method Overriding is the best example of dynamic polymorphism. It is also called dynamic binding or late binding, because type of the object used will be determined at run time only.
https://javaconceptoftheday.com/polymorphism-in-java/
Encapsulation in Java
http://www.tutorialspoint.com/java/java_encapsulation.htm