Thread: Query on what I did wrong

  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
    3,445
    this is not a java forum. what makes you think you can post java code here and get help with it?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  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
    587
    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, 09:06 AM
  5. Query
    By Nsofu_mm in forum C++ Programming
    Replies: 0
    Last Post: 01-25-2002, 06:12 AM