Posts

Showing posts from December, 2022

Encaspsulation

Image
        Data Protect (Data Hiding)     Encapsulation is a concept used to protect data. Then, we use encapsulation to protect our        data and store them safely.   Why do we use a capsule to store medicine in it?    Because we need to protect medicine, we use a capsule.   In this scenario, medicine is the code, capsule is the concept Encapsulation.   What is data protect?   Accessing only in present class (The class that the data is located)    When data protecting other classes can't access the data whose outside the related class.   Refer to this code sample give below,     class Human {    private int id;    private string name ;    private int age;     }    class RunProgramme {   public static void main (String[]args) {    Human h = new Human ();    h.id = 3567231567;    h.name = "Kamal"...

Interfaces

Image
I have explained you in a past article about Inheritance. But here I'm going to talk about Multiple Inheritance.  Multiple Inheritance is extending one class to many classes. But its not allowed in Java. As a solution OOP gave us Interfaces. Interface is like a class (That means it has all the features that a class have) But Interface is not a class. We can use Interfaces in /java if we need to use multiple inheritance. Java has no limit for multiple inheritance using Interfaces. but when we are inheriting  Interfaces we use the keyword implements not extends Creating an Interface Ex :- 1)        Interface Saman {                                 } We create an interface in the way we are creating a class. Inheriting an Interface to a Class Ex :- 2)    class A {                   }           ...

Abstract Classes

Image
When we're coding, we will meet methods that we can't apply codes, So we can name them as Meaningless Methods . We can't store meaningless methods in an ordinary way. In that situation, We have to make Abstract methods using the keyword "Abstract". We can't store Abstract methods in an ordinary class. Therefore, we have to make the class also an abstract class using Abstract keyword. We can store abstract methods only in abstract classes. But we can store any method in an abstract class. The important thing is, we cannot create objects in an abstract class .  Refer to the code sample given below, Abstract class Vehicle{ abstract void park (); } Abstract class Vehicle { Abstract void park (); void reverse (){ } } There is a code inside the meaningless method highlighted with Orange like , Ex :-  class Vehicle {           void park (){           }           } The part highlighted in blue is a meaningless ...