Why cant we call base class constructor without creating object of derived class in multiple inheritance (java) -


this question has answer here:

class {   public a()   {...} }  class b extends {   public b(string s)   {...} }  class c extends b {   public c()   {...} }  class const {   public static void main(string a[])   {       b object=new b("hello"); // gives error.   } } 

why compiler giving error ->
error.java:18: error: constructor b in class b cannot applied given types; class c extends b ^ required: string
found: no arguments
reason: actual , formal argument lists differ in length
1 error

you have call constructor of child

constructor creates object of type, if call parent constructor able create parent instace. thats why not allowed , have rewrite c class follows:

class c extends b {     public c(string s)     {         super(s);         ...     } } 

note: error in case:

c object=new c("hello"); // gives error. 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -