java - Error: Constructor A in class A cannot be applied to given types -


public class a{      public a(string x){         system.out.println("a constructor called "+x);     }      public static void main(string []args){         system.out.println("hello world");         a= new b("b");      } }  class b extends a{     public b(string x){         system.out.println("b constructor called "+x);     } } 

what problem in simple program, unable locate it. getting following error on compile:

a.java:13: error: constructor in class cannot applied given types;                                                                                                         public b(string x){                                                                                                                                                                                ^                                                                                                                                                            required: string                                                                                                                                                                 found: no arguments                                                                                                                                                              reason: actual , formal argument lists differ in length   

since class not have default constructor, need tell class b how construct parent:

class b extends a{     public b(string x){         super(x);  // constructs parent class         system.out.println("b constructor called "+x);     } } 

the error telling constructor must call requires string:

required: string

... 1 calling (which the default constructor because not calling super ) has no arguments:

found: no arguments


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -