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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:23:31+00:00 2026-06-09T09:23:31+00:00

In terms of values for properties defined in the super class using the same

  • 0

In terms of values for properties defined in the super class using the same property in the sub-class and the property is defined as protected, then using super or this does not make any difference right? Then why does the language really have these ways of accessing the properties? Is there a scenario where they will have different values?

class A {
    protected int a = 15; 
}
        
class B extends A { 
    public void printA() {
        System.out.print(super.a) // prints 15
        System.out.print(this.a) // prints 15
    }
}
  • 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-09T09:23:33+00:00Added an answer on June 9, 2026 at 9:23 am

    In this situation, it doesn’t make any difference. However, as soon as you change to methods instead of variables, and introduce another method in B which shadows the one in A, then it makes a difference:

    class A { 
        protected int a = 15; 
    }
    
    class B extends A { 
        private int a = 10;
    
        public void printA() {
           System.out.println(super.a); // prints 15
           System.out.println(this.a); // prints 10
        }
    }
    

    This is more common with methods than with fields though – often an overriding implementation needs to call the superclass implementation as part of its implementation:

    public void foo() {
        super.foo();
        // Now do something else
    }
    

    I would personally recommend avoiding non-private fields, at which point the field part becomes irrelevant.

    See section 6.4.1 of the JLS for more on shadowing.

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

Sidebar

Related Questions

I have two objects of the same type and need to copy property values
I get this error sometimes, Catchable fatal error: Object of class stdClass could not
In terms of SQL terminology, does HEAP stands for a table that has Non-Clustered
It seems that licensing terms would prevent us from using Google Maps API in
I need to dynamically bind properties of components created at runtime. In this particular
I'm dynamically creating some <div> elements and then filling their innerHTML properties with text.
I have a location class. This class basically holds addresses, hence the term location.
What I have: List Class: Rule --> Class: Term ---> Property Compare_Src Property Compare_Mode
Here´s the background, maybe some of the terms are incorrect, as I´m not an
As I'm not very experienced in terms of retrieving information from the Active Directory

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.