Welcome to Dream.In.Code
Become a Java Expert!

Join 149,519 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,376 people online right now. Registration is fast and FREE... Join Now!




How do I extend an Abstact class and use its methods

 
Reply to this topicStart new topic

How do I extend an Abstact class and use its methods, abstract(concrete) questions

dbrine
26 May, 2007 - 07:42 PM
Post #1

New D.I.C Head
*

Joined: 25 Apr, 2007
Posts: 48


My Contributions
I'm trying to create a concrete (abstract) class. I've looked around but I can't really find anything that helping me(NOOB here). I will post the code below I have already

1. create a concrete class, Cat, which inherits from another class. cat has 2 instance variables, both strings: name, which has private access and breed is has protected access.

CODE

public class Cat extends Animal
{
    public Cat
    {
        private String name;
        protected String breed;
    }
}


EDIT: Modified title to be more descriptive ~ jayman9
User is offlineProfile CardPM
+Quote Post

spullen
RE: How Do I Extend An Abstact Class And Use Its Methods
26 May, 2007 - 09:18 PM
Post #2

D.I.C Regular
Group Icon

Joined: 22 Mar, 2007
Posts: 330



Thanked: 1 times
Dream Kudos: 50
My Contributions
now implement all the functions that Animal has.

User is offlineProfile CardPM
+Quote Post

dbrine
RE: How Do I Extend An Abstact Class And Use Its Methods
27 May, 2007 - 01:23 PM
Post #3

New D.I.C Head
*

Joined: 25 Apr, 2007
Posts: 48


My Contributions
this is what I have now, but I get an error. I'll post the Animal abstract class below the Cat class below.

cannot find symbol
symbol : constructor Animal()
location: class Animal

CODE

public class Cat extends Animal
{
    private String name;
    protected String breed;

    public Cat()
    {

    }

    public String describe()
    {
        return new String(",a breed of Cat called" +cat);
    }

    public String sound()
    {
        return new String("Meow");
    }

    public String sleep()
    {
        return new String("Kitty is having purfect dreams!");
    }

    public String move()
    {
        return new String("This little Kitty moves fast!");
    }
}



CODE



public abstract class  Animal
{
    public Animal(String type)
    {
        //super(type);
    }

    public abstract String describe();

    public abstract String sound();

    public abstract String sleep();

    public abstract String move();
}




QUOTE(spullen @ 26 May, 2007 - 10:18 PM) *

now implement all the functions that Animal has.


User is offlineProfile CardPM
+Quote Post

Jayman
RE: How Do I Extend An Abstact Class And Use Its Methods
27 May, 2007 - 02:24 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,303



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Abstract classes cannot be instantiated and therefore do not need a constructor unless you are planning to access the constructor from a subclass. A subclass is a class that can be instantiated into an object.

Read section "8.1.1.1 abstract Classes" at the following link for more info.
http://java.sun.com/docs/books/jls/second_...lasses.doc.html

Otherwise change the constructor to be the default that doesn't take any parameters.
CODE

public Animal()


User is offlineProfile CardPM
+Quote Post

oubless
RE: How Do I Extend An Abstact Class And Use Its Methods
28 May, 2007 - 06:30 AM
Post #5

New D.I.C Head
*

Joined: 28 May, 2007
Posts: 23


My Contributions
One of these:
in Animal:
CODE
public Animal(){
...
}

or in Cat:
CODE
public Cat(){
   super("Cat"); // probably that is what you mean under type
}

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:13PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month