Posts

Showing posts from March, 2024

Object Oriented Programming - JAVA - Abstract / Abstract classes

Image
Object Oriented Programming - JAVA👽 Abstract / Abstract classes ..... Abstraction in OOPS is used to hide unnecessary information and show only necessary information to interacting users. We can modify a class or method into abstract class or abstract method using Abstract keyword. Let's continue this discussion using example code in the below. class Vehicle {    void park(){   } } class Bicycle extends Vehicle {    void park(){      // break      // putting a foot on the ground      // getting off the bike   } } A bodyless method is in the Vehicle class because it needs to be overridden.   Open and closing curly brackets are not needed for the method because it is bodyless.  But we can't use like  void park(); , That's why we look like a command using method run.  When we use Abstract keyword, we can show bodyless methods without open and closing curly brackets. So we can show that "...

Object Oriented Programming - JAVA - Polymorphism

Image
  Object Oriented Programming - JAVA 👽 Polymorphism is the ability of any data to hold more than one form. Plural means many, and morph means the same word as categories. Polymorphism is an important concept in object-oriented programming languages. Before when we learn polymorphism, we have to know about override and casting. If you have no idea about those things then you can use below links.  Method Override Blog -  https://miyurangika1223.blogspot.com/2024/02/object-oriented-programming-java-method.html Casting Blog -  https://miyurangika1223.blogspot.com/2024/03/object-oriented-programming-java-casting.html After overriding a method in a superclass in a subclass, the process of upcasting and calling the subclass method through the superclass reference is called Polymorphism. class A {   void print (){     sout ("A");   } } class B extends A{    void print (){     sout ("B");   } } class Test {   public stat...

Object Oriented Programming - JAVA- Casting

Image
Object Oriented Programming - JAVA👽 Casting ...... We use casting to catch a class using another class. So in this blog we discuss about Casting.      What's going on in Casting  ? In casting, we have to inherit classes. Let's see an example.     int x  = 5 ;     Integer variables have 32 bits.     long y = 6 ;      Long variables have 64 bits.         x = y ; ✖      We can't catch long variable using integer variable.    y = x ;   ✔      We can catch integer variable using long variable. There are two types of casting. Upcasting Downcasting Upcasting     Upcasting is a process of assign subclass object to superclass variable that is reference of superclass.  class Parent {     //code } class Child extends Parent {      //code } class Test {      Parent p = new Child(); } The object always runs i...