Like Tree1Likes
  • 1 Post By Elkvis

Query on what I did wrong

This is a discussion on Query on what I did wrong within the Tech Board forums, part of the Community Boards category; // This is for Circle.Java Code: package Circle; public class Circle { private double radius; public Circle() { radius = ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    17

    Query on what I did wrong

    // This is for Circle.Java
    Code:
    package Circle;
    public class Circle {
    private double radius;
    public Circle() 
    {
    radius = 2.0;
    }
    public double getRadius()
    {
    return radius;
    }
    public double getArea() 
    {
    return radius*radius*Math.PI;
    }
    public void printMe() 
    {
    System.out.println("ID is 2015");
    }
    }
    //This is for Cylinder.Java
    Code:
    package Circle;
    public class Cylinder extends Circle {
        private double height;
    public Cylinder() 
    {
    super();
    height = 2.5;
    }
    public double getHeight() 
    {
    return height;
    }
    public double getVolume() 
    {
    return height*getArea();
    }
    @Override
    public void printMe() 
    {
    System.out.println("Color is blue");
    }
    void print()
    {
    .printMe();
    .printMe();
    }
    public static void main(String[] args){
    Cylinder cy1 = new Cylinder();
    System.out.println("Radius is " + cy1.getRadius()+" Height is " + cy1.getHeight()+ " Base area is " + cy1.getArea()+ " Volume is " + cy1.getVolume());
    cy1.print();
    }
        
    }
    My
    Code:
    package Circle;
    is being underlined in both file.

    In my Cylinder.java , I do not understand the part where it says
    Code:
    void print()
    {
    .printMe(); //I am suppose to type something in front but i don't know what I'm suppose to
    .printMe(); //I am suppose to type something in front but i don't know what I'm suppose to
    }
    Help would be appreciated, did I miss out something in some part of my code>

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    2,457
    this is not a java forum. what makes you think you can post java code here and get help with it?
    Elysia likes this.
    Code:
    namespace life
    {
        const bool change = true;
    }

  3. #3
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Use the super keyword to access a method/field of a class' superclass. I don't remember much about packages but your folder structure should resemble the package structure (so your stuff should be in some folder named Circle...I think).

    I guess users not posting compiler errors doesn't really vary with language.

  4. #4
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    500
    Smells like homework. Anyways as 4 days has passed now, here are some hints/tips:
    1) You are using identifier "Circle" as both class name & package name
    2) Try "this" & "super" before "." and try to figure out what the program is doing when each keyword is used
    3) Indent your code
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. l-value query
    By sed_y in forum C Programming
    Replies: 2
    Last Post: 08-27-2011, 04:01 PM
  2. Query where is the wrong
    By Leite33 in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2006, 06:16 AM
  3. ARP Query
    By arron in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-14-2005, 11:11 PM
  4. SQL Query
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 12-24-2003, 08:06 AM
  5. Query
    By Nsofu_mm in forum C++ Programming
    Replies: 0
    Last Post: 01-25-2002, 05:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21