• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

please help me from this code

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont know why and where the error occurs.
so please tell me
 
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13013
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13013
66
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic