Java Multiple Inheritance
Multiple inheritance is not supported in java. But we can achieve multiple inheritances through an interface.
Syntax:
interface interface_name1{ // declare constant fields // declare methods that abstract } interface interface_name2{ // declare constant fields // declare methods that abstract } class class_name implements interface_name1,interface_name2{ // fields // methods }
Example:-
interface Roll { int rollno = 10; } interface Name { String name = "Sundarrajan"; void showdata(); } class Student implements Name,Roll { public void showdata() { System.out.println(rollno+" "+name); } } public class Multipleinheritance{ public static void main(String args[]) { Student s1=new Student(); s1.showdata(); } }
Learn more details about the interface.
Quickly Find What You Are Looking For
Onlinetpoint is optimized for basic learning, practice and more. Examples are well checked and working examples available on this website but we can't give assurity for 100% correctness of all the content. This site under copyright content belongs to Onlinetpoint. You agree to have read and accepted our terms of use, cookie and privacy policy.