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 9304419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:42:15+00:00 2026-06-18T23:42:15+00:00

I need to program a parent class (Plate) and some child classes (WoodenPlate, PorcelainPlate,

  • 0

I need to program a parent class (Plate) and some child classes (WoodenPlate, PorcelainPlate, etc) each of the Child Objects should have a serial number starting with 1, then 2, etc.
Where should I store this information? Can I just increment a counter in the Parent Object?

  • 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-06-18T23:42:16+00:00Added an answer on June 18, 2026 at 11:42 pm

    This is how your one of your Child class should look like:

    class WoodenPlate extends Plate {
        private static int counter = 0;
        private int serialNumber;
    
        public WoodenPlate() {
            serialNumber = ++counter;
        }
    }
    

    And then for each instance of WoodenPlate, you can access the serialNumber using public accessors

    You can define rest of your Child classes like this. With each one of them having a static counter and a serialNumber field.


    If you don’t want the count to start from 1 fro every Child, but just want the count to continue from the previous one regardless of which Child class was instantiated, then you should have those fields in Parent class:

    class Parent {
        protected static int counter = 0;
        protected int count;
    
        public int getCount() {
            return count;
        }
    }
    

    And then remove the field from each of your Child class.

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

Sidebar

Related Questions

In my program I need to programmatically configure an ApplicationContext. Specifically, I have a
I'm making a task-based program that needs to have plugins. Tasks need to have
I'm using QT to implement some UI program. In this program I need a
All objects in my program inherit from a Container class. The Container class has
I need a program that checks if the difference between all pairs of elements
I need my program to create and edit a config file, which would contain
I need my program to see different colors. Pretty much all I need is
I need a program that reads from multiple files and displays a report based
I need to generate multiple databases to SQL, so I need script/program to automatically
I'm doing a theatrical performance, and I need a program that can read images

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.