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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:31:56+00:00 2026-05-29T05:31:56+00:00

We can access the Super Class methods which consists of operations on private data

  • 0

We can access the Super Class methods which consists of operations on private data members and print the results.But why can’t I print the private data members of Super Class with the SubClass object calling them in my main function? Someone please explain me.

Here is the example below.

class SuperClass1
{
    private int a;
    private int b;

    SuperClass1(int p,int q)
    {
        a=p;
        b=q;
    }
    SuperClass1(SuperClass1 obj)
    {
        a=obj.a;
        b=obj.b;
    }
    SuperClass1()
    {
        a=-1;
        b=-1;
    }

    int Vol()
    {
        return a*b;
    }
}

class SubClass1 extends SuperClass1
{
    int c;

    SubClass1(int p,int q,int r)
    {
        super(p,q);
        c=r;
    }
    SubClass1(SubClass1 obj)
    {
        super(obj);
        c=obj.c;
    }
    SubClass1()
    {
        super();
        c=-1;
    }
}


public class Super 
{
    public static void main(String[] args) 
    {
        SubClass1 obj1=new SubClass1();
        //System.out.println("The values of obj1 are:"+obj1.a+""+obj1.b+""+obj1.c);
        int vol=obj1.Vol();
        System.out.println("The volume is :"+vol);
    }
}
  • 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-05-29T05:31:57+00:00Added an answer on May 29, 2026 at 5:31 am

    security and encapsulation

    The superclass is letting its subclasses use only the public and protected methods/fields.

    This allows the designer of the superclass to change the implementation of these methods if he sees it better, without breaking the subclass’s correctness.

    A text book example is a complex number class.

    The programmer using this class only needs its functionality, he doesn’t care if the implementation is with imaginary and real fields or with radius and theta fields [two distinct ways to represent complex number].

    It allows the designer of the ComplexNumber class more freedom if he wants to change the class in later versions, and it also allows the user less worries: he doesn’t need to take care for all the details, some are being taken care of for him.

    Bonus: note you can break this behavior and access private fields and methods by using reflection – but when you do so – all bets are off, and you do it on your own responsibility.

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

Sidebar

Related Questions

How can hibernate can access a private field/method of a java class , for
I can access and show self.view and see the frame in the log but
I know you can access the Contact Store from the SDk, but is it
Lets say I have the following class structure in my data access layer: interface
Super easy question. Look at the 2 sample class methods. In the first One
I have set of classes which inherit from a single super class: Super |
I can access the database either from a .NET program (using ODBC) or through
I can access Spring beans in my Servlets using WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); in
Can anyone let me know how can access an element of a list that
In PHP you can access characters of strings in a few different ways, one

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.