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

  • Home
  • SEARCH
  • 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 8402055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:57:15+00:00 2026-06-09T21:57:15+00:00

Here is an example : class Parent { protected int A; public void displayA()

  • 0

Here is an example :

class Parent {
    protected int A;

    public void displayA() {
        System.out.println(A);
    }
}

class Child extends Parent {
    protected static int A=2;
}

Child intance = new Child();
intance.displayA();

=> return null !!!

What is the way to retrieve the child attribute from parent method ?

Thank you 🙂

  • 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-09T21:57:16+00:00Added an answer on June 9, 2026 at 9:57 pm

    In your instance if you use your Child class constructor to set the value of A rather than redeclaring the variable then the parent class should be able to get the value.

    The problem with the instance above is that you are redeclaring the variable in your sub class rather than just altering the value of the variable in your superclass.

    Is there a reason that you have the child variable declared as static? If you only need the value of that class variable then you can reference it directly. However a neater way to have the potential for multiple subclasses to set the variable value and it be used by the super class is to have the child classes set the value you want and then have the super class reference that variable (possibly using a getter) that the subclass has set the value of.

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

Sidebar

Related Questions

Here is code example class A{ int i; public: A(int i) : i(i) {}
See the following example (PHP) class Parent { protected $_property; protected $_anotherP; public function
here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
Here is an example of what I would do in Visual Basic: Public Class
Here is example: class A { public long ParentId; public string ParentName; public string
I have a parent class that is also a factory. For example: Public Class
Here's some example code: class Obj attr :c, true def == that p '=='
I just wanted to confirm the difference here, take this as an example: class
I'm trying to comprehend ontology basics. Here's an example: car (class) 2009 VW CC
I've written a complex search form in Django. Here is my example model: class

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.