×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Java Inheritance Java String Methods Part 1
Java Method Overriding - Java
3138    Arnab De    19/07/2017

What is function or method overriding?

Two functions can define with the same name and prototype, one placed in the super class and another one placed in the subclass. The method of the subclass was written for altering or modifying the task of the super class. This feature of object oriented programming is known as method overriding.

public class Human
{
public void say()
{
System.out.println("It is super class version");
}
}

public class Indian extends Human
{
public void say()
{
System.out.println("It is sub class version");
}
}

public class TestHumanIndian
{
public static void main(String [] args)
{
Indian i =new Indian();
i.say();
}
}

softetechnologies

Note: If the method of the super class declared as final then that method cannot be override in sub class.

Note: If we call an overridden method then it normally invokes the sub class version of the method. A keyword, super is used to invoke the super class version method.

softetechnologies
public class Human
{
public void say()
{
System.out.println("It is super class version");
}
}

public class Indian extends Human
{
public void say()
{
System.out.println("It is sub class version");
}
void TestCall()
{
say();
super.say();
}
}

public class TestHumanIndian
{
public static void main(String [] args)
{
Indian i =new Indian();
i.TestCall();
}
}


In which condition method cannot be overridden?

If the function or method declared as static or final then that method cannot be overridden. Static methods can redesign but not overridden.

Note: Constructor cannot be overridden.
Note: abstract methods must be overridden at the first non-abstract class.
softetechnologies


What is the difference between Method Overloading vs overriding?

In overloading both the function placed in the same class. The names of the functions are same but the prototype, specially signature of the methods are different. But in overriding methods are placed different classes, one in super class and another one in sub class. But the name and prototype are the same for the both of the functions.

Java Inheritance Java String Methods Part 1
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
What makes one man great and another weak and low is shraddha (concentration).
Swami Vivekananda
1044
60.61
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     44721
01/01/2018     36882
25/06/2018     36855
28/06/2017     34896
02/08/2017     33491
01/08/2017     27840
06/07/2017     27613
15/05/2017     27180
14/07/2017     22943
11/09/2018     21679
softetechnologies