Site icon C1CTech

Java Inheritance

<p>In this tutorial&comma; we will learn about inheritance in Java with the help of examples&period;<&sol;p>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>Inheritance<&sol;strong><&sol;span><&sol;h3>&NewLine;<p><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">Java <span style&equals;"color&colon; &num;008000&semi;"><strong><span style&equals;"color&colon; &num;0000ff&semi;">Inheritance<&sol;span> <&sol;strong><&sol;span>is one of the key feature of <strong><span style&equals;"color&colon; &num;0000ff&semi;">OOP <&sol;span>&lpar;Object Oriented Programming&rpar;<&sol;strong>&period; <strong><span style&equals;"color&colon; &num;008000&semi;">Inheritance<&sol;span> <&sol;strong>can be defined as the process where one class is allowed to inherit the features &lpar;fields and methods&rpar; of another class&period; <&sol;span><&sol;p>&NewLine;<p>Inheritance supports the concept of &OpenCurlyDoubleQuote;<strong><span style&equals;"color&colon; &num;008000&semi;">reusability<&sol;span><&sol;strong>”&comma; i&period;e&period; The code that is present in the parent class doesn’t need to be written again in the child class&period;<&sol;p>&NewLine;<p>The class which inherits the features of other class is known as <strong><span style&equals;"color&colon; &num;008000&semi;">sub class<&sol;span> <&sol;strong>&lpar;or a derived class or a child class&rpar;&period;<&sol;p>&NewLine;<p>The class whose features are inherited is known as <span style&equals;"color&colon; &num;008000&semi;"><strong>super class<&sol;strong> <&sol;span>&lpar; or a base class or  a parent class&rpar;&period;<&sol;p>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Syntax<&sol;strong><&sol;span><&sol;h5>&NewLine;<pre>class Subclass-name <span style&equals;"color&colon; &num;0000ff&semi;"><strong>extends<&sol;strong> <&sol;span>Superclass-name&NewLine; &lbrace;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;methods and fields <&sol;span> <&sol;strong>&NewLine; &rcub;<&sol;pre>&NewLine;<p>In Java&comma; we use the <span style&equals;"color&colon; &num;008000&semi;"><strong>extends<&sol;strong> <&sol;span>keyword to inherit features from a super class in sub class&period;<&sol;p>&NewLine;<h5><strong><span style&equals;"color&colon; &num;0000ff&semi;">Example<&sol;span><&sol;strong><&sol;h5>&NewLine;<pre><span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;Calculator is a super class<&sol;strong><&sol;span>&NewLine;class <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Calculator<&sol;strong> <&sol;span>&lbrace;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;Calculator class members<&sol;span><&sol;strong>&NewLine; public int add&lpar;int x&comma; int y&rpar; &lbrace;&NewLine; return x &plus; y&semi;&NewLine; &rcub;&NewLine;&NewLine; public int sub&lpar;int x&comma; int y&rpar; &lbrace;&NewLine; return x - y&semi;&NewLine; &rcub;&NewLine;&rcub;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;CalcAdv is a sub class<&sol;span><&sol;strong>&NewLine;class <strong><span style&equals;"color&colon; &num;0000ff&semi;">CalcAdv <&sol;span><&sol;strong><span style&equals;"color&colon; &num;000000&semi;">extends Calculator<&sol;span>&lbrace;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;CalcAdv class members<&sol;span><&sol;strong>&NewLine; public int sqr&lpar;int x&rpar; &lbrace;&NewLine; return x &ast; x&semi;&NewLine; &rcub;&NewLine;&NewLine; public double sqrt&lpar;float y&rpar; &lbrace;&NewLine; return Math&period;sqrt&lpar;y&rpar;&semi;&NewLine; &rcub;&NewLine;&NewLine;&rcub;&NewLine;&NewLine;public class Main &lbrace;&NewLine;&NewLine; public static void main&lpar;String args&lbrack;&rsqb;&rpar; &lbrace;&NewLine;&NewLine; <strong> <span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;creating CalcAdv object<&sol;span><&sol;strong>&NewLine; CalcAdv calcAdv &equals; new CalcAdv&lpar;&rpar;&semi;&NewLine;&NewLine; System&period;out&period;println&lpar;"The sum of the given numbers&colon; " &plus; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>calcAdv&period;add&lpar;10&comma; 20&rpar;<&sol;strong><&sol;span>&rpar;&semi;&NewLine; System&period;out&period;println&lpar;"The difference between the given numbers&colon; " &plus; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>calcAdv&period;sub&lpar;30&comma; 20&rpar;<&sol;strong><&sol;span>&rpar;&semi;&NewLine; System&period;out&period;println&lpar;"The square of a given number&colon; " &plus; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>calcAdv&period;sqr&lpar;10&rpar;<&sol;strong><&sol;span>&rpar;&semi;&NewLine; System&period;out&period;println&lpar;"The square root of a given number&colon; " &plus; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>calcAdv&period;sqrt&lpar;25&rpar;<&sol;strong><&sol;span>&rpar;&semi;&NewLine;&NewLine; &rcub;&NewLine;&rcub;<&sol;pre>&NewLine;<h5><strong><span style&equals;"color&colon; &num;0000ff&semi;">Output<&sol;span><&sol;strong><&sol;h5>&NewLine;<pre>The sum of the given numbers&colon; 30&NewLine;The difference between the given numbers&colon; 10&NewLine;The square of a given number&colon; 100&NewLine;The square root of a given number&colon; 5&period;0<&sol;pre>&NewLine;<h5><strong><span style&equals;"color&colon; &num;0000ff&semi;">Example explained<&sol;span><&sol;strong><&sol;h5>&NewLine;<ul>&NewLine;<li>Here&comma; we have inherited a subclass <span style&equals;"color&colon; &num;0000ff&semi;"><strong>CalcAdv<&sol;strong> <&sol;span>from super class <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Calculator<&sol;strong><&sol;span>&period; The <span style&equals;"color&colon; &num;008000&semi;"><strong>CalcAdv<&sol;strong> <&sol;span>class inherits the methods <span style&equals;"color&colon; &num;008000&semi;"><strong>add&lpar;&rpar;<&sol;strong><&sol;span> and <strong><span style&equals;"color&colon; &num;008000&semi;">sub&lpar;&rpar;<&sol;span><&sol;strong> from the <strong><span style&equals;"color&colon; &num;008000&semi;">Calculator <&sol;span><&sol;strong>class&period;<&sol;li>&NewLine;<li><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">When an object of <span style&equals;"color&colon; &num;008000&semi;"><strong>CalcAdv<&sol;strong> <&sol;span><&sol;span><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">class is created&comma; a copy of all methods and fields of the super class acquire memory in this object&period; That is why by using the object of the subclass we can also access the members of a super class&period;<&sol;span><&sol;li>&NewLine;<li><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">Hence&comma; objects of the <span style&equals;"color&colon; &num;008000&semi;"><strong>CalcAdv<&sol;strong> <&sol;span>class can access the members of <strong><span style&equals;"color&colon; &num;008000&semi;">Calculator<&sol;span> <&sol;strong>class&period;<&sol;span><&sol;li>&NewLine;<&sol;ul>&NewLine;<h4><&sol;h4>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>Types of Inheritance in Java<&sol;strong><&sol;span><&sol;h3>&NewLine;<p>There are various types of inheritance in Java&colon;<&sol;p>&NewLine;<h4><span style&equals;"color&colon; &num;000080&semi;"><strong>Single Inheritance<&sol;strong><&sol;span><&sol;h4>&NewLine;<p>In single Inheritance&comma; a class inherits features of another class &lpar;one class only&rpar;&period;<&sol;p>&NewLine;<p><img class&equals;" wp-image-1877 aligncenter" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;05&sol;single&lowbar;inheritance&lowbar;img&period;png" alt&equals;"single&lowbar;inheritance&lowbar;img" width&equals;"320" height&equals;"271" &sol;><&sol;p>&NewLine;<p>In above diagram&comma; Class B extends only Class A&period; Class A is a super class and Class B is a Sub class&period;<&sol;p>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Example&colon; Single Inheritance<&sol;strong><&sol;span><&sol;h5>&NewLine;<pre><span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;Person is a super class<&sol;strong><&sol;span>&NewLine;class Person &lbrace;&NewLine;&NewLine; private String name&semi;&NewLine; private int age&semi;&NewLine;&NewLine; public String getName&lpar;&rpar; &lbrace;&NewLine; return name&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setName&lpar;String name&rpar; &lbrace;&NewLine; this&period;name &equals; name&semi;&NewLine; &rcub;&NewLine;&NewLine; public int getAge&lpar;&rpar; &lbrace;&NewLine; return age&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setAge&lpar;int age&rpar; &lbrace;&NewLine; this&period;age &equals; age&semi;&NewLine; &rcub;&NewLine;&NewLine;&rcub;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Student is a sub class<&sol;span><&sol;strong>&NewLine;class Student extends Person &lbrace;&NewLine;&NewLine; private int rollno&semi;&NewLine;&NewLine; public int getRollno&lpar;&rpar; &lbrace;&NewLine; return rollno&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setRollno&lpar;int rollno&rpar; &lbrace;&NewLine; this&period;rollno &equals; rollno&semi;&NewLine; &rcub;&NewLine;&NewLine;&rcub;&NewLine;&NewLine;public class Main &lbrace;&NewLine; public static void main&lpar;String&lbrack;&rsqb; args&rpar; &lbrace;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;creating Student instance<&sol;span><&sol;strong>&NewLine; Student student &equals; new Student&lpar;&rpar;&semi;&NewLine; student&period;setRollno&lpar;101&rpar;&semi;&NewLine; student&period;setName&lpar;"Arun Verma"&rpar;&semi;&NewLine; student&period;setAge&lpar;18&rpar;&semi;&NewLine;&NewLine; System&period;out&period;println&lpar;"Rollno&colon; " &plus; student&period;getRollno&lpar;&rpar;&rpar;&semi;&NewLine; System&period;out&period;println&lpar;"Name&colon; " &plus; student&period;getName&lpar;&rpar;&rpar;&semi;&NewLine; System&period;out&period;println&lpar;"Age&colon; " &plus; student&period;getAge&lpar;&rpar;&rpar;&semi;&NewLine;&NewLine; &rcub;&NewLine;&rcub;<&sol;pre>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Output<&sol;strong><&sol;span><&sol;h5>&NewLine;<pre>Rollno&colon; 101&NewLine;Name&colon; Arun Verma&NewLine;Age&colon; 18<&sol;pre>&NewLine;<h4><&sol;h4>&NewLine;<h4><span style&equals;"color&colon; &num;000080&semi;"><strong>Multilevel Inheritance<&sol;strong><&sol;span><&sol;h4>&NewLine;<p>In Multilevel Inheritance&comma; a sub class inherits all the properties and behaviours of more than one super class at multiple levels&period;<&sol;p>&NewLine;<&excl;-- WP QUADS Content Ad Plugin v&period; 2&period;0&period;98&period;1 -->&NewLine;<div class&equals;"quads-location quads-ad2" id&equals;"quads-ad2" style&equals;"float&colon;none&semi;margin&colon;0px&semi;">&NewLine;&NewLine;<&sol;div>&NewLine;&NewLine;<p><img class&equals;" wp-image-1880 aligncenter" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;05&sol;multilevel&lowbar;inheritance&lowbar;img&period;png" alt&equals;"multilevel&lowbar;inheritance&lowbar;img" width&equals;"343" height&equals;"382" &sol;><&sol;p>&NewLine;<p>In above diagram&comma; Class A is a super class of Class B and Class B is a super class of Class C or Class C is a subclass of Class B and Class B is a subclass of Class A&period;<&sol;p>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Example&colon; Multilevel Inheritance<&sol;strong><&sol;span><&sol;h5>&NewLine;<pre><span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;Person is a super class of Student<&sol;strong><&sol;span>&NewLine;class <strong><span style&equals;"color&colon; &num;0000ff&semi;">Person<&sol;span> <&sol;strong>&lbrace;&NewLine; private String name&semi;&NewLine; private int age&semi;&NewLine;&NewLine; public String getName&lpar;&rpar; &lbrace;&NewLine; return name&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setName&lpar;String name&rpar; &lbrace;&NewLine; this&period;name &equals; name&semi;&NewLine; &rcub;&NewLine;&NewLine; public int getAge&lpar;&rpar; &lbrace;&NewLine; return age&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setAge&lpar;int age&rpar; &lbrace;&NewLine; this&period;age &equals; age&semi;&NewLine; &rcub;&NewLine;&NewLine;&rcub;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;Student is a sub class of Person and super class of School<&sol;strong><&sol;span>&NewLine;class <strong><span style&equals;"color&colon; &num;0000ff&semi;">Student<&sol;span> <&sol;strong>extends Person &lbrace;&NewLine;&NewLine; private int rollno&semi;&NewLine;&NewLine; public int getRollno&lpar;&rpar; &lbrace;&NewLine; return rollno&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setRollno&lpar;int rollno&rpar; &lbrace;&NewLine; this&period;rollno &equals; rollno&semi;&NewLine; &rcub;&NewLine;&NewLine;&rcub;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;School is a sub class of Student<&sol;strong><&sol;span>&NewLine;class <strong><span style&equals;"color&colon; &num;0000ff&semi;">School<&sol;span> <&sol;strong>extends Student &lbrace;&NewLine;&NewLine; private String schoolName&semi;&NewLine; private String standard&semi;&NewLine; private char section&semi;&NewLine;&NewLine; public String getSchoolName&lpar;&rpar; &lbrace;&NewLine; return schoolName&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setSchoolName&lpar;String schoolName&rpar; &lbrace;&NewLine; this&period;schoolName &equals; schoolName&semi;&NewLine; &rcub;&NewLine;&rcub;&NewLine;&NewLine;public class Main &lbrace;&NewLine;&NewLine; public static void main&lpar;String&lbrack;&rsqb; args&rpar; &lbrace;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;creating School object<&sol;strong><&sol;span>&NewLine; School school &equals; new School&lpar;&rpar;&semi;&NewLine; school&period;setName&lpar;"Rohit Verma"&rpar;&semi;&NewLine; school&period;setRollno&lpar;102&rpar;&semi;&NewLine; school&period;setSchoolName&lpar;"Global Public School"&rpar;&semi;&NewLine;&NewLine; System&period;out&period;println&lpar;"Name&colon; " &plus; school&period;getName&lpar;&rpar;&rpar;&semi;&NewLine; System&period;out&period;println&lpar;"Rollno&colon; " &plus; school&period;getRollno&lpar;&rpar;&rpar;&semi;&NewLine; System&period;out&period;println&lpar;"School Name&colon; " &plus; school&period;getSchoolName&lpar;&rpar;&rpar;&semi;&NewLine;&NewLine; &rcub;&NewLine;&rcub;<&sol;pre>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Output<&sol;strong><&sol;span><&sol;h5>&NewLine;<pre>Name&colon; Rohit Verma&NewLine;Rollno&colon; 102&NewLine;School Name&colon; Global Public School<&sol;pre>&NewLine;<h4><&sol;h4>&NewLine;<h4><span style&equals;"color&colon; &num;000080&semi;"><strong>Hierarchical Inheritance<&sol;strong><&sol;span><&sol;h4>&NewLine;<p>In hierarchical inheritance&comma; two or more classes inherits a single class&period;<&sol;p>&NewLine;<p><img class&equals;" wp-image-1881 aligncenter" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;05&sol;hierarchical&lowbar;inheritance&lowbar;img&period;png" alt&equals;"hierarchical&lowbar;inheritance&lowbar;img" width&equals;"558" height&equals;"247" &sol;><&sol;p>&NewLine;<p>In above diagram&comma; class B&comma; C&comma; D inherit the same class A&period;<&sol;p>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Example&colon; Hierarchical Inheritance<&sol;strong><&sol;span><&sol;h5>&NewLine;<pre><strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Person is a super class of Student and Teacher<&sol;span><&sol;strong>&NewLine;class <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Person<&sol;strong> <&sol;span>&lbrace;&NewLine; private String name&semi;&NewLine; private int age&semi;&NewLine;&NewLine; public String getName&lpar;&rpar; &lbrace;&NewLine; return name&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setName&lpar;String name&rpar; &lbrace;&NewLine; this&period;name &equals; name&semi;&NewLine; &rcub;&NewLine;&NewLine; public int getAge&lpar;&rpar; &lbrace;&NewLine; return age&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setAge&lpar;int age&rpar; &lbrace;&NewLine; this&period;age &equals; age&semi;&NewLine; &rcub;&NewLine;&NewLine;&rcub;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;Student is a sub class of Person<&sol;strong><&sol;span>&NewLine;class <strong><span style&equals;"color&colon; &num;0000ff&semi;">Student<&sol;span> <&sol;strong>extends Person &lbrace;&NewLine;&NewLine; private int rollno&semi;&NewLine;&NewLine; public int getRollno&lpar;&rpar; &lbrace;&NewLine; return rollno&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setRollno&lpar;int rollno&rpar; &lbrace;&NewLine; this&period;rollno &equals; rollno&semi;&NewLine; &rcub;&NewLine;&NewLine;&rcub;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;Teacher is a sub class of Person<&sol;strong><&sol;span>&NewLine;class <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Teacher<&sol;strong> <&sol;span>extends Person &lbrace;&NewLine;&NewLine; private int salary&semi;&NewLine;&NewLine; public int getSalary&lpar;&rpar; &lbrace;&NewLine; return salary&semi;&NewLine; &rcub;&NewLine;&NewLine; public void setSalary&lpar;int salary&rpar; &lbrace;&NewLine; this&period;salary &equals; salary&semi;&NewLine; &rcub;&NewLine;&rcub;&NewLine;&NewLine;public class Main &lbrace;&NewLine; public static void main&lpar;String&lbrack;&rsqb; args&rpar; &lbrace;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;creating Student object<&sol;strong><&sol;span>&NewLine; Student student &equals; new Student&lpar;&rpar;&semi;&NewLine; student&period;setRollno&lpar;101&rpar;&semi;&NewLine; student&period;setName&lpar;"Arun Verma"&rpar;&semi;&NewLine; student&period;setAge&lpar;18&rpar;&semi;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;creating Teacher object<&sol;span><&sol;strong>&NewLine; Teacher teacher &equals; new Teacher&lpar;&rpar;&semi;&NewLine; teacher&period;setSalary&lpar;15000&rpar;&semi;&NewLine; teacher&period;setName&lpar;"Sachin Sharma"&rpar;&semi;&NewLine; teacher&period;setAge&lpar;30&rpar;&semi;&NewLine;&NewLine; System&period;out&period;println&lpar;"Student Name&colon; " &plus; student&period;getName&lpar;&rpar; &plus; " &vert; " &plus; "Rollno&colon; " &plus; student&period;getRollno&lpar;&rpar; &plus; " &vert; " &plus; "Age&colon; " &plus; student&period;getAge&lpar;&rpar;&rpar;&semi;&NewLine; System&period;out&period;println&lpar;"Teacher Name&colon; " &plus; teacher&period;getName&lpar;&rpar; &plus; " &vert; " &plus; "Salary&colon; " &plus; teacher&period;getSalary&lpar;&rpar; &plus; " &vert; " &plus; "Age&colon; " &plus; teacher&period;getAge&lpar;&rpar;&rpar;&semi;&NewLine;&NewLine; &rcub;&NewLine;&rcub;<&sol;pre>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Output<&sol;strong><&sol;span><&sol;h5>&NewLine;<pre>Student Name&colon; Arun Verma &vert; Rollno&colon; 101 &vert; Age&colon; 18&NewLine;Teacher Name&colon; Sachin Sharma &vert; Salary&colon; 15000 &vert; Age&colon; 30<&sol;pre>&NewLine;<h5><&sol;h5>&NewLine;<h4><span style&equals;"color&colon; &num;000080&semi;"><strong>Multiple Inheritance<&sol;strong><&sol;span><&sol;h4>&NewLine;<p>In Multiple inheritance&comma; one class can have more than one super class and inherit features from all parent classes&period;<&sol;p>&NewLine;<p><img class&equals;" wp-image-1883 aligncenter" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;05&sol;multiple&lowbar;inheritance&period;png" alt&equals;"multiple&lowbar;inheritance" width&equals;"502" height&equals;"220" &sol;><&sol;p>&NewLine;<p>In above diagram&comma; Class C extends Class A and Class B both&period;<&sol;p>&NewLine;<h4><span style&equals;"color&colon; &num;000080&semi;"><strong>Hybrid Inheritance<&sol;strong><&sol;span><&sol;h4>&NewLine;<p>Hybrid Inheritance is a mix of two or more of the above types of inheritance&period;<&sol;p>&NewLine;<p><img class&equals;" wp-image-1885 aligncenter" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;05&sol;hybrid&lowbar;inheritance&lowbar;img&period;png" alt&equals;"hybrid&lowbar;inheritance&lowbar;img" width&equals;"512" height&equals;"322" &sol;><&sol;p>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;000080&semi;"><strong>Note<&sol;strong><&sol;span>&colon; Java does not support Multiple and Hybrid inheritance with classes&period; In java&comma; we can achieve both inheritance only through Interfaces&period;<&sol;p>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;&NewLine;

Exit mobile version