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 2 of 2

Thread: Apple

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Apple

    Below is what I have to do and the code is what I have done...I am having trouble with the parts in red... Can someone help me and tell me how to fix it..or show me how to fix it.Thank You!




    C. Write a program, which consists of following three classes and one interface.

    • Class Fruit with following members:
    o protected String color;

    o protected double weight;

    o public abstract String getColor();

    o public abstract double getWeight();


    • Interface Edible has only one abstract method getTaste().

    • An Apple class inherits Fruit and implements Edible.

    • A test class called TestApple will create an instance of Apple and call all above abstract methods and print out an apple object’s color, weight, and taste.



     
    import javax.swing.*;
    import java.awt.*;
     
    public class Fruit
    {
    private String color;
    private double weight;
     
    Fruit(){}
    Fruit(String color, double weight)
    {
    this.color=color;
    this.weight=weight;
    }
     
    public String getcolor()
    {
    return  color;
    }
     
    public double getweight()
    {
    return weight;
    }
     
    public interface Edible
    {
    	public abstract void getTaste();
    }
     
    class Apple extends Fruit 
    {
    public String getTaste()
    {
    return null;
    }
     
    public class TestApple
    {
    public void main(String[] args)
    {
    	Apple Apple1 = newApple();
    [COLOR="Red"]	Apple1.getColor();
    	Apple1.getWeight();
    	Apple1.getTaste();
     
    System.out.println();
    System.out.println ("Apple Color is: " + Fruit.getColor() );
    System.out.println ("Apple Weight is: " + Fruit.getWeight() );
    System.out.println ("Apple Taste is: " + Fruit.getTaste() + ".");[/COLOR]
    }
    }
    }
    }


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

    Default Re: Apple

    Your parent class fruit is not abstract. It needs to be declared abstract as well as have the abstract methods outlined in the description. This will force the compiler to let you know Apple does not implement those methods, which you need to implement to be able to access those methods.