Hi there,

I am Rohan!

""""✰I am always blown away to see thought leaders like Rohan with ambition, having a positive impact on the world!"✰ Michael Walmsley, CEO and founder of CodeAvengers.
Join Rohan Chaubey on

Method Overriding, Constructor Overloading, Scanner class!

In our previous blogs we studied about Characteristics of Java, How to install Java, Classes, Objects, White Spaces, Data Types, Variables and Array Of Objects. Click here to go to our previous Posts!  

Let us Begin... 

In this Blog we are going to see what is Method Overriding, Constructor Overloading and Scanner Class. 

What is Method Overriding ? 

Method overriding occurs when we have the exactly same methods in super as well as sub class. The benefit of overriding is: ability to define a behavior that's specific to the subclass type which means a subclass can implement a parent class method based on its requirement. In object-oriented terms, overriding means to override the functionality of an existing method. How to implement overriding in a java program ? Click Here! 

Remember : Overriding is defined as when a subclass method provides three things which are the same as in the overridden method :
(1) method name, and
(2) parameter list, and
(3) return type.
Overriding is also called Shadowing! 

Constructor Overloading : 

As we have already studied in C++ that a constructor is nothing but a special member function with the same class name which initializes the data members of the class. It is invoked automatically whenever the object of its class is created. There are different types of Constructor used in java. 
  1. Default Constructor. (No Argument Constructors).
  2. Parameterized Constructor.
So, The main difference between a default constructor and an Parameterized constructor is that the default constructor cannot hold any arguments whereas passing arguments to Parameterized constructor is possible. 

Now,  let us discuss what is constructor overloading... Same as method overloading, constructor overloading means having more that one that is multiple constructors in a single class. But the arguments of the constructor might differ.

For programs on constructor overloading Click Here! 

Remember : You cannot mark constructors void or static. They can only be public, private, or protected.

Scanner Class : 

The java.util.Scanner class is a simple text scanner which can parse primitive types and strings using regular expressions. This class is mainly used for receiving input from the user. Know more about Scanner Class!

Program For Scanner Class :
import java.util.Scanner;
class RohanScan
     public static void main(String[] args)
            String temp="";
            String name="";
            Scanner in=new Scanner(System.in);
            String str[]={"first", "middle","last"};
            for(int i=0;i<3;i++)
            System.out.println("Enter your "+str[i]+" name");
            name+=" "+temp;
    System.out.println("Your full name is: "+name);

Output Of Scanner Class

Happy Learning. Have a great day! 

ABOUTRohan Chaubey

Rohan Chaubey is the founder of “Be Rohanlicious” – a blog that teaches you to be smart with social media, blogging and programming.

Rohan is on a mission to help all the enthusiastic souls like you, who want to “make it to the next level” and stand out of the crowd.

His e-book “Make People Want You” is releasing soon. Allow him to inject awesomeness in your life by signing up to his list here.