Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why this basic code not compiled, Any one Identify Please..  RSS feed

 
jami siva
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This code is not compiled , any one please tell me what wrong with this code :



Thanks ..
Sivva
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you have a close look at the error that the compiler gives you?

Your class Cls has one constructor that takes a String. Your class Cls1 extends class Cls. In order to create a Cls1 object, the constructor of the superclass Cls has to be called. But you didn't specify in the constructor of Cls1 which constructor of Cls should be called, so Java tries to find the default (no-args) constructor of class Cls. But class Cls doesn't have a no-args constructor, so you get an error.

You can solve this by putting a call to super(...); in the constructor of Cls1, for example:

 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A friendly tip for next time:

It GREATLY helps people help you if you post the exact text of the error you receive. Those few lines of text actually tell a lot once you learn how to read it, and if you post it, others can narrow in on the problem much faster. That, in turn, makes them more likely to help you.

 
jami siva
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Jesper ,i forgot this basic thing.
and fred rosenberger also, for given me a valuable suggestion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!