×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Java Inheritance Java String Methods Part 1
Java Method Overriding - Java
2572    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.
Albert Einstein
Pure mathematics is, in its way, the poetry of logical ideas.
Albert Einstein
110
44.94
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     36731
01/01/2018     34923
28/06/2017     32404
02/08/2017     30469
25/06/2018     30215
15/05/2017     25401
01/08/2017     24701
06/07/2017     24612
14/07/2017     20225
21/04/2018     19839
softetechnologies