Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: I CANT COMPILE

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I CANT COMPILE

    well guys this is my code
     public class MyBox extends Box
        {
            public MyBox(double x)
            {
                if(this.x >0){
                super(x);
            }
            }
            public double volume()
            {
                return height*height*height;
            }
            public double calculate()
            {
                return 6*height*height;
            }
            public String toString()
            {
                return "Cube Calculation " +calculate()+ ", Volume " +volume();
            }
        }
    the code doesnt work if i have this if statement. If i make the if comments the super(x); works fine. ( super(x); calls a method from the Box class. please help. In compiler it says cannot find symbol - constructor Box
    Last edited by copeg; March 31st, 2011 at 10:54 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: I CANT COMPILE

    In the future please use the code tags, which make your code readable.

    What is Box? Does it have the constructor you are calling? Second, super must be the first call made in the constructor.

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I CANT COMPILE

    Well yes the constructor i call yes there is in the Box class. The Box construtctor takes a double x and it creates a cube. all i want to do is to prevent the Box to create a cube if i a negative value is given...

  4. #4
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I CANT COMPILE

    Problem solved thx

Similar Threads

  1. class wont compile
    By waspandor in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 15th, 2011, 04:40 PM
  2. *why won't this compile?*
    By dcshoecousa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 2nd, 2010, 07:18 PM
  3. [SOLVED] help in java i cant compile this
    By timeline in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 15th, 2010, 02:11 PM
  4. Game of Craps: won't compile
    By FreeBird in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 15th, 2010, 05:12 PM
  5. need help to compile
    By hardwarewizard in forum Java Theory & Questions
    Replies: 0
    Last Post: February 14th, 2010, 10:03 AM