Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 683411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:42:15+00:00 2026-05-14T01:42:15+00:00

I need to create class Dog and PurebredDog extending Dog. Problem is that Dog

  • 0

I need to create class Dog and PurebredDog extending Dog. Problem is that Dog can be at once single object and array of objects (Dogs and PurebreedDogs :

 Dog pack[]={new Dog(76589,"As","black",18,
                    "Ann","Kowalsky"),
           new PurebreedDog(45321,"Labrador","Elf","black",25, 
                          "Angus","Mati","Barbara","Smith"),
           new Dog(102467,"Gamma","brown",89,
                    "Josh","Coke"),
            new PurebreedDog(9678,"York","Theta","brown",8,
                    "Emka","Figaro","Alice","Cat")};    

for(int i=0; i < pack.length; i++)
  System.out.println(pack[i]+"\n\n");

How to write proper constructor for Dog ?
You could do :

public Dog(String name, etc){
}

but how to write constructor for array of dogs ?

public Dog(Dog[]tab) ?

And then how to recall it’s elements ? Is pack[] a 2d array ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:42:15+00:00Added an answer on May 14, 2026 at 1:42 am

    To simplify things, an instance of Dog really should refer to a single Dog. So your constructor should look similar to (the data types are just examples):

    Dog(int ID, String color, String name, ...)
    

    PurebreedDog would subclass Dog and provide any additional constructor parameters (and members) such as breed, etc.

    To deal with multiple dogs, I recommend you store instances of the class in a List, HashTable, or other type of data structure that is designed to hold multiple elements. The actual structure you use will depend upon your requirements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a class that can be accessible through the ASP Classic
I need to create at runtime instances of a class that uses generics, like
Into a class constructor, I need to create some objects on the fly and
Need to create a class that will do all things as the merge function.
I need to create a class that represent SVN inside a module called SCM.
I need to create a class that will present a UIVIew and has a
I create a linq to sql class Create all entities that i need for
I need to create a multi-dimensional array which will be passed to a class.
I am pretty new to python. I need to create a class that loads
I need to create a class object dynamically. I attempted this using the dynamic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.