Posts

Showing posts with the label oop

Java Polymorphism

Image
                                  Polymorphism After Overriding a method of a super-class in a sub-class, Upcasting it, and running the sub-class method through a super-class reference is called polymorphism.

Java upcasting and Downcasting

Image
                      Upcasting  and Downcasting    Upcasting The process of adding a sub-class object to a super-class reference variable is called upcasting . A    a = new B();      Downcasting   The process of getting a sub-class object  placed in a  super         class variable back to the same sub-class reference is called downcasting . B b = (B) a ; For additional information 👇

Java Method Overriding

Image
 Method Overriding   Let us compare  a Man and a Monkey. Changing the body of a Method passed from a super class to a sub class is called Method Overriding . Example 👇 Here the class called Man is Inherited from the class called Monkey .

Java Method Overloading

Image
 Method Overloading   A  Method is something that groups a coding set and keeps it. Let's create 2 Methods now. ( same class ).     ( But  it is not allowed to create more than one method with the same name in the same class ) Even though we are not allowed to create more than one method with the same name in the same class, we create it anyway. Creating multiple methods with the same name in the same class ( changing the parameters  signature ) is called  Method Overloading . We can do method overriding by changing the parameters inside the methods. Example 1 👇 Since we have been given an integer argument of 5 , it will be called at the ( 1)   Example 2 👇 Since we have not put an integer argument here, it will be called at (2) Example 3 👇 If you put an integer argument, it will be called at   (1). If you put two integer arguments, it will be called at   (2). If we change the parameters, we can grab them separately when calling . Example 4 👇

Java Access Modifiers

Image
                    Access Modifiers This is how we create security by knowing  who accesses a Class , Variable  or Method . Types Of Access Modifiers 1)Public 2)Protected 3)Default 4)Private Public Any class can be access from anywhere. Protected It is visible to the class  it is in and its subclasses and to others in the package it is in. Default Only the class you are in and the people in the package you are in can see. Private Only people in their class can see it. Example 👇                                                                                                                                                   Here class B is Inherited   from class A . Here    class   D is  Inherited   from   class C . Here, if  class A is Private, other   classes and packages cannot access it.  Here , if  class A is Default , B and C classes can access it. (Same package) Here , if   class C  is  Default , they are visible (can access)  to class C,B and A .  can't visible (can

Java Inheritance

Image
                                    Inheritance Using the things in one class of the program we are making in another class. Example: Old and New phone 👇 After inherit 👇 Types Of Inheritance 1) Single Inheritance 2) Multilevel Inheritance 3) Hierarchical Inheritance Single Inheritance Things in one class are used in another class. Here  class B  has Inherited from  class A . class A   operates as a " Superclass" and class B as a " Subclass".  class B can use the " Variables " and " Methods" of class A  Multilevel Inheritance There are Three classes here. class A   works as a" Superclass"  and  class B  and  class C   as a " Subclass".  And when  class C   works as a " Subclass " ,  class   B  works as a " Superclass ". class B can use  the" Variables " and " Methods " of class A class C  can use the " Variables " and " Methods " of  class B class C can use