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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:37:35+00:00 2026-06-05T15:37:35+00:00

if we have 2 class Zoo & Moo as follows: public class zoo {

  • 0

if we have 2 class Zoo & Moo as follows:

public class zoo {
    String superString="super";
    private String coolMethod(){
        return "Zoo method";
    }
}

public class Moo extends zoo{
    public void useMyCoolMethod(){
        zoo z=new zoo();
        System.out.println(superString);//1
        System.out.println(z.superString);//2
    }
    public  static void main(String[]args){
        new Moo().useMyCoolMethod();
    }
}

at 1 & 2 we print the value of the String in the super class through inheritance and access, the question is , what is the benefit of Access although i can do the same thing by inheritance ? knowing that the Access approach isn’t allowed if the two classes is in diff packages

  • 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-05T15:37:37+00:00Added an answer on June 5, 2026 at 3:37 pm

    By accessing through the object ref you are modifying the referenced object’s state, by inheritance you are modifying the object you are currently in ( this reference ). So there is actually no benefit aside from encapsulation at class level and package level through out the access modifiers and that sort of thing, you just use it depending on the behavior you want for you’re code, or in this case, how restrictive to modify the state of objects depending on the context.

    But aside from that, i’m not sure if there is anything else.

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

Sidebar

Related Questions

I have class with back reference: public class Employee : Entity { private string
I have class EventManager with method: public function addEvent(obj:IEventDispatcher, event:String, listener:Function, useCapture:Boolean = false,
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have class for iterating images. public class PictureManager { private int _current; public
I have: class first{ private: int *array; public: first(int x){ array = new int[x][10];
Let's say I have this class: class Zoo { protected String bearName; protected Double
I have class ! class Reg_v_no_string { public static string key_place = ; public
I have class in Java: class data { private String id; private String name;
I have a yearmon object: require(zoo) date1 <- as.yearmon(Mar 2012, %b %Y) class(date1) #
I have class Meat extends Food { $var = Food::foodFunction… } I need to

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.