Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please help me from this code

 
Rajesh Km
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh Km wrote:
help me with this prog.i am new to java


What exactly do you need help with? Please take care to TellTheDetails and UseRealWords when asking questions.
 
Rajesh Km
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i AM GETTING THESE ERRORS
.\Triangle.java:9: error: constructor Shape in class Shape cannot be applied to given types;
{
^
required: int,int
found: no arguments
reason: actual and formal argument lists differ in length
.\Square.java:7: error: constructor Shape in class Shape cannot be applied to given types;
{
^
required: int,int
found: no arguments
reason: actual and formal argument lists differ in length
.\Circle.java:7: error: constructor Shape in class Shape cannot be applied to given types;
{
^
required: int,int
found: no arguments
reason: actual and formal argument lists differ in length
 
Rajesh Km
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont know why and where the error occurs.
so please tell me
 
Henry Wong
author
Marshal
Pie
Posts: 21510
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh Km wrote:i AM GETTING THESE ERRORS
.\Triangle.java:9: error: constructor Shape in class Shape cannot be applied to given types;
{
^
required: int,int
found: no arguments
reason: actual and formal argument lists differ in length



Basically, this error is saying that your Triangle class is trying to use the the default constructor of shape class -- but your shape class doesn't have a default constructor. Your shape class has a constructor that takes two int parameters.

Henry
 
Rajesh Km
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks its working know.but a doubt if we dont provide the constructor Java virtual machine automatically creates one default constructor and initiates the parent constructor.then why in this case it didnt work
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because if you provide a constructor with parameters, then the compiler will NOT insert the default constructor and you will have to explicitly write it like you just did.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12202
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are only given a default constructor if you DON'T create one yourself. In your shape class, you made one that takes two ints:

So you don't get a free, no-arg one.
 
Rajesh Km
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this mandatory or if we want to access the no arg constructor we need to provide
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it is not mandatory, provided the superclass of class Shape, has a default constructor. This is because the first statement of any constructor, by default is a call to super().
 
drac yang
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this code just cannot be compiled with prompt of eclipse: Implicit super constructor Shape() is undefined. Must explicitly invoke another constructor.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12202
35
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
drac yang wrote:this code just cannot be compiled with prompt of eclipse.

but most beginners don't (and shouldn't) use eclipse.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic