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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:00:00+00:00 2026-06-11T05:00:00+00:00

Possible Duplicate: Hiding instance variables of a class I have below class AbstractTest public

  • 0

Possible Duplicate:
Hiding instance variables of a class

I have below class

AbstractTest

public abstract class AbstractTest {
 protected int testVar = 10;
}

Test

public class Test extends AbstractTest {
int testVar = 5;

public static void main(String[] args) {
    AbstractTest test = new Test();
    System.out.println(test.testVar);//Prints 10

    Test secondTest = new Test();
    System.out.println(secondTest.testVar);//Prints 5
}
}

Why above program prints 10 for first case and 5 for second case though it is object of same class i.e. Test()?

Update:

I am now confused about how memory is allocated to Object and its variables. As instance variable is getting changed based on Class which is behaviour of Static?

Update:1

Every object will have two variables so question of same memory allocation does not comes in to picture. Thanks.

  • 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-11T05:00:01+00:00Added an answer on June 11, 2026 at 5:00 am

    This is defined in JLS 15.11.1

    [In the expression Primary.Identifier], only the type of the Primary expression, not the class of the actual object referred to at run-time, is used in determining which field to use.

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

Sidebar

Related Questions

Possible Duplicate: jQuery and pseudo-classes I tried hiding the :after pseudo class via jQuery
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Abstraction VS Information Hiding VS Encapsulation The definitions of abstraction and encapsulation
Possible Duplicate: What are the differences between struct and class in C++ http://www.cplusplus.com/reference/std/typeinfo/type_info/ I
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: iPhone Documents directory and UIFileSharingEnabled, hiding certain documents I want the user
Possible Duplicate: Hiding textarea resize handle in Safari in textarea input the user can
Possible Duplicate: Why do I get a null pointer exception from TabWidget? I have
Possible Duplicate: name hiding and fragile base problem I'm familiar with the rules involving

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.