




























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Facts about inheritance in Java.
Typology: Study notes
1 / 68
This page cannot be seen from the preview
Don't miss anything!





























































Inheritance
public class Employee { String name; int age; double salary; public void printData(){ System.out.println("name: " + name); System.out.println("age: " + age); System.out.println("salary: " + salary); } } public class Programmer extends Employee { String language; public void printData(){ super.printData(); System.out.println("language: " + language); } } public class DatabasePro extends Employee { String databaseTool; public void printData(){ super.printData(); System.out.println("Database Tool: " + databaseTool); } }
3
These are all Animals so will make Animal – Super Class Instance Variables - Picture , Food , Hunger, Location Methods – makenoise() , eat() , Sleep(), roam()
Method overriding - Definition
Overloading Overriding (^1) Whenever same method or Constructor is existing multiple times within a class either with different number of parameter or with different type of parameter or with different order of parameter is known as Overloading. Whenever same method name is existing multiple time in both base and derived class with same number of parameter or same type of parameter or same order of parameters is known as Overriding. (^2) Arguments of method must be different at least arguments. Argument of method must be same including order. (^3) Method signature must be different. Method signature must be same. (^4) Private, static and final methods can be overloaded. Private, static and final methods can not be override. (^5) Also known as compile time polymorphism or static polymorphism or early binding. Also known as run time polymorphism or dynamic polymorphism or late binding. (^6) Overloading can be exhibited both are method and constructor level. Overriding can be exhibited only at method label. (^7) The scope of overloading is within the class. The scope of Overriding is base class and derived class. (^8) Overloading can be done at both static and non-static methods. Overriding can be done only at non-static method. (^9) For overloading methods return type may or may not be same. For overriding method return type should be same. Difference between Overloading and Overriding
Using super to call base class constructor
Constructors Call
Animal an; an = myDog; an.roam();