Basic Project - Learning Process
In this project I introduced Object Oriented Programming. I learned Constructor , Inheritance, Encapsulation, Polymorphism, Abstract and Interface.
Bu projede Nesneye Yönelik Programlamaya giriş yaptım. Constructor , Inheritance, Encapsulation, Polymorphism, Abstract ve Interface yapılarını öğrendim.
// Information about OOP is as follows.
A constructor in Java is a special method that is used to initialize objects. The constructor is called when an object of a class is created.
Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object. It is an important part of OOPs (Object Oriented programming system). The idea behind inheritance in Java is that you can create new classes that are built upon existing classes.
Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction.
Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding.
To achieve encapsulation in Java
-Declare the variables of a class as private.
-Provide public setter and getter methods to modify and view the variables values.
In Java, polymorphism refers to the ability of a class to provide different implementations of a method, depending on the type of object that is passed to the method. To put it simply, polymorphism in Java allows us to perform the same action in many different ways.
The abstract keyword is a non-access modifier, used for classes and methods: Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class). Abstract method: can only be used in an abstract class, and it does not have a body.
An interface in Java is a blueprint of a class. It has static constants and abstract methods. The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body.