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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:34:16+00:00 2026-06-01T22:34:16+00:00

I need a parent public abstract class which will have multiple child public static

  • 0

I need a parent public abstract class which will have multiple child public static classes. I need only one instance of a Weapon class, a few static classes Bow, Sword< etc which extend the parent and can exist also only in one instance (at least I need to be able to get their static fiels). How to do it properly?

public abstract  class Weapon {
    ...
}
public static class Bow extends  Weapon { 
      static String type = "Bow ";
      static  int damage = 10;
}

public static class Sword extends  Weapon { 
      static String type = "Sword";
      static int damage = 10;
}

Getting error:

Illegal modifier for the class Sword; only public, abstract & final are permitted

I removed static and it worked:

public final class   Sword extends  Weapon { 
      static String type = "Sword";
      static int hitPointsTaken = 10;
}

I can compile this System.out.println( Sword.type ); but not this System.out.println( Weapon.Sword.type ); . Does it mean that I cannot access child through parent abstract?

  • 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-01T22:34:18+00:00Added an answer on June 1, 2026 at 10:34 pm

    If you absolutely have to implement this model, you’re looking at nesting:

    public abstract  class Weapon {
    
        public static class Bow extends  Weapon { 
              static String type = "Bow ";
              static  int hitPointsTaken = 10;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
I have an abstract parent class(Product) and two child classes that inherit from it(Book,Software).
I have a parent class, like this: public abstract class Business<T> : IBusiness<T> where
I have a need to close a parent form from within child form from
I have a data object which has a base class with three derived classes,
I have an abstract class BaseItem declared like this: public abstract class BaseItem {
How does this child class access the parent class within livewallpaper service. public class
Let's say I have an abstract parent class called shape, and that there are
I have the following: class Parent { public: virtual bool foo(vector<string> arg1, vector<string> arg2)
If I have this structure: public class Parent { public string Name{get; set;} public

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.