Posts

Showing posts from January, 2024

Java OOPC - Casting

Image
  Casting   Casting is what assigning data types in hierarchical way. That means we cannot assign big type to small type data. If we said in a detailed way in we cannot assign first place data type in hierarchy to last data types in  hierarchy.     Upcasting and Downcasting     Two essential concepts in OOP are upcasting and downcasting, which involve the manipulation of object references and inheritance.   Upcasting    Upcasting involves treating an object of a derived class as an object of its base class. In simpler terms, it's moving up the class hierarchy. This is inherently safe, as every instance of the derived class is also an instance of the base class. Consider the following example in Java,   Upcasting is the   process of assigning the object from sub class to the variable in the form of Super class reference. Always object run from the class of the object created.so because of that the final...

Java OOPC - Method Overriding & Super Keyword

Image
  Method Overriding   The process of changing the body of   method that inherit From superclass to subclass is called as the Method overriding. Method overriding is a concept in object-oriented programming that allows a subclass to provide a specific implementation of a method that is already defined in its superclass.   For overriding classes should be inherit. so because of that parent class properties and behaviours are claimed to child class. In here inside the sub class same method repeat two times. One is overrided sub class method and other is inherit method from parent class. However, the overrided sub class method only runing and did not run the method inherit from parent class.   In a class first the the main method runing. Secondly   the Object is runing If we did not create any object JVM create a object from itself. Then Constructor runing and it is also if we did not create JVM itself created. Lastly normal methods are runing a...

Java OOPC - Inheritance

Image
  Inheritance   In real life inheritance is what that father and mother features genetic things got there babies also along those he or she get unique features. If we apply that to the java concept inheritance is that parent class method , properties inherit into the child classes.   In  other way can tell Inheritance allows you to create a new class that inherits properties and behaviour from an existing class. It is like that passing on the family traits . It promotes code reusability. In simply manner we can tell inheritance is how one class connect with another class.   Derived Class/Sub-class: Derived class is a class that inherits from a base class. It is also known as subclass or child class.  Base Class/Superclass:  ​ The base class is the main class where derived classes inherit the features. It is also known as the superclass or parent class.    Properties and methods in the super class inherit to the sub cl...

Java OOPC -Method Overloading

Image
    Method Overloading         In a same class we can keep same name methods with different parameters  this concept we called it as Method Overloading or can tell as Method Signature Changing.  In because of the different parameters ,Method considered as completely different method from the same name other methods.   In other way can tell that Method overloading is a concept of  Java  in which we can create multiple methods of the same name in the same class, and all methods work in different ways.  When more than one method of the same name is created in a Class, this type of method is called the Overloaded Method.   In bellow sample code we can understand overloading in different views, Advantages of method overloading 1.       Increases the readability of the program. 2.       Makes the code cleaner and well-structured. 3.       Provides...

Java OOPC -Java Constructor

Image
  Java Constructor     In Java, a constructor is a special type of method that is used to initialize objects. It is called when an object of a class is created, and its primary purpose is to set initial values for the object's attributes.   In further we can tell constructor is a method that create using the class name and it have not any return type while constructor is work on the time when object is called. It is a special type of method which is used to initialize the object.   In simply pointed view we can understand constructor is what Method Name same of the class name No need return type     There are two type of constructors mainly, 1.Parameter less constructor 2.Parameterize constructor 1. Parameter less constructor   In other way we can tell it as default constructor. If a class does not have any constructor defined, Java provide the parameter less constructor. In this constructor there is no parameters a...