Mastering Java and Spring Boot - Live Course : https://bit.ly/TeluskoJavaLive
For More Queries WhatsApp or Call on : +919008963671
In this lecture we are discussing:
#1 method overriding
#2 Necessary condition for method overriding
What is method Overriding?
It is way to override the parent class method in child class .
class Parent{
int a;
public void show{System.out.println("this is parent");}
}
class Child extends Parents{
int a=10; //override a
public void show(){System.out.println("this is child method");} //method override by child class
}
class Main{
public static void main(String []args){
Child c=new Child();
c.show(); //call the child class override method
}
}
-- method overriding is run time polymorphism
-- it is use to increase the reusability of code
#2
for a method to be overridden, the following conditions must be met:
-- The method in the subclass must have the same signature (name, number and type of parameters) as the method in the superclass.
-- The method in the subclass must have the same return type (or a subtype) as the method in the superclass.
-- The method in the subclass must have the same access level (public, protected, or private) as the method in the superclass.
-- The method in the subclass must not be static, while the method in the superclass must be marked as non-final.
-- The overridden method must be visible from the subclass it means you can change access modifiers but there is condition for
-- you need to increase visibility but you cannot reduced it , you can do it using access modifiers.
-- you can change access modifiers in this manner
private -default -protected -public (in upcoming lecture access modifiers has been discussed)
for knowing about access modifiers wait for access modifiers lecture in this playlist
class A{
void show(){ // -- by default access modifier is default
System.out.println("A");
}
int a=5;
}
class B extends A{
protected void show(){ //-- access modifier is protected --we can increase visibilty
System.out.println("B");
}
}
Github repo : https://github.com/navinreddy20/Javacode.git
Java:- https://bit.ly/JavaUdemyTelusko
Spring:- https://bit.ly/SpringUdemyTelusko
More Learning :
Java :- https://bit.ly/3x6rr0N
Python :- https://bit.ly/3GRc7JX
Django :- https://bit.ly/3MmoJK6
JavaScript :- https://bit.ly/3tiAlHo
Node JS :- https://bit.ly/3GT4liq
Rest Api :-https://bit.ly/3MjhZwt
Servlet :- https://bit.ly/3Q7eA7k
Spring Framework :- https://bit.ly/3xi7buh
Design Patterns in Java :- https://bit.ly/3MocXiq
Docker :- https://bit.ly/3xjWzLA
Blockchain Tutorial :- https://bit.ly/3NSbOkc
Corda Tutorial:- https://bit.ly/3thbUKa
Hyperledger Fabric :- https://bit.ly/38RZCRB
NoSQL Tutorial :- https://bit.ly/3aJpRuc
Mysql Tutorial :- https://bit.ly/3thpr4L
Data Structures using Java :- https://bit.ly/3MuJa7S
Git Tutorial :- https://bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
https://www.telusko.com