#52 Method Overriding in Java

Check out our courses: Mastering Agentic AI with Java : https://go.telusko.com/agentic-ai Coupon: TELUSKO10 (10% Discount) DevOps Bootcamp: https://go.telusko.com/complete-devops Coupon: TELUSKO10 (10% Discount) Master Java Spring Development : https://go.telusko.com/learn-master Coupon: TELUSKO10 (10% Discount) For More Queries WhatsApp or Call on : +919008963671 website : https://telusko.com/ Udemy Courses: Java Spring:- https://go.telusko.com/Udemyjavaspring Java:- https://go.telusko.com/udemyteluskojava Spring: https://go.telusko.com/udemyteluskosp... Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopy... Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodo... Instagram :   / navinreddyofficial   Linkedin :   / navinreddy20   WhatsApp : https://go.telusko.com/whatsapp TELUSKO Android App : https://go.telusko.com/TELUSKOAPP TELUSKO IOS App : https://apple.co/3SsgmU2 Discord :   / discord   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/Javac... 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