Posts

Showing posts from January, 2024

Object Oriented Programming - JAVA- Inheritance

Image
 Object Oriented Programming - JAVA👽     In this blog we will discuss about inheritance in java programming. Through this blog, you can get an idea about what is "inheritance", why we use inheritance, how we use inheritance in coding. So, let's start. Inheritance..... The process of relating one class to another is called inheritance.  In inheritance we need to know mainly two types of classes. Super class Sub class Superclass is the class that gives its properties and behavior, in other words variables and methods. The superclass is also called the parent class. Subclasses inherit the variables and methods of the superclass. A subclass is also called a child class. Sub class can take all the things of super class but super class cannot take things of sub class. If the super class has private thing, sub class can't get that. Sub classes have new variables and methods that not in super class. Let me give simple example for it. Father has a car. when the inherita...

Object Oriented Programming - JAVA - Method Overloading

Image
Object Oriented Programming - JAVA 👽 In Java, sometimes we have to use methods with the same name. So how do we use such methods without any errors? Today we are talking about these situations. Method Overloading..... What is method overloading?  When it is necessary to have several methods with the same name in the same class, by changing the parameters of those methods, it is possible to keep those methods as separate methods. This practice is called method overloading. This method overloading also known as signature changing.  When we overload the method, there are three basic  things we need to take care of the parameters. Number of parameters Datatype of parameters Sequence of parameters Let's look at examples of changing parameters. Number of parameters :        class A {            void display (int a ){                  //  only one parameters    ...

Object Oriented Programming - JAVA- Constructor

Image
  Object Oriented Programming - JAVA 👽 The constructor is the first thing that runs in a program. Is it true❓ You can answer this at the end of this discussion.  Let's talk about constructor Constructor... A constructor is something that holds everything in the program. There are several features in this. It is created by the name of the class No return type is required It's a method            class Sun{                 Sun(){                     // constructor                }                   public static void main (String [] args){                        Sun s = new Sun();                     }       ...

Object Oriented Programming - JAVA- class boundary, variable types, modifiers, java main method

Image
Object Oriented Programming - JAVA👽 There are certain aspects of Object Oriented Programming. So when we use OOP we need to know about those elements. In this blog, Let's discuss about class, variables, modifiers and methods & main method . Class.... A class is a blueprint that defines common variables and methods for objects of a particular type. A class has a boundary. Inside this boundary we only have the class, constructor and main method. Even if a method is in the class, we cannot take it to the class boundary. Variables.... Variables   are used to store information to be referenced and manipulated in a computer program. There are two variable types. Static variable Non - static variable Static variable The easiest way to find static variable is to find out if there is a static key ward.      ex :         static int i ; These can be accessed anywhere within the class. It can be accessed even without creating an object. Non - ...