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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:49:54+00:00 2026-05-20T10:49:54+00:00

Is it possible to a class has a method that can only be called

  • 0

Is it possible to a class has a method that can only be called by it’s objects and hidden for a subclass object? For instance:

class ClassOne {
    ... // attributes

    public void doSomething() { ... }
}

class ClassTwo extends ClassOne {
    ... // attributes and methods
}

ClassOne c1 = new ClassOne();
c1.doSomething(); // ok to call

ClassTwo c2 = new ClassTwo();
c2.doSomething(); // forbidden

I know this seems weird thinking in therms of inheritance, but is it possible?

PS: the objective of this question is just to learn more about inheritance of OO programming.

  • 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-20T10:49:54+00:00Added an answer on May 20, 2026 at 10:49 am

    It’s not possible and your right that this would break inheritance. Think about

    ClassOne c2 = new ClassTwo();
    c2.doSomething(); // what to do?
    

    This has to work because ClassTwo is a ClassOne. Edit: at least is has to compile, if the method is overridden and does something else is up to your design. But you cannot make the compiler produce an error on this.

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

Sidebar

Related Questions

A Castle Windsor question: Is it possible to register a class that has an
In C#, is it possible to extend a class that has no constructors? Maybe
Is it possible to globalize an instance which has been declared in a Class?
I've got a class that represents a document (GH_Document). GH_Document has an AutoSave method
I have a base class that has a method that gets executed by derived
is it possible in java to have a class where it has EventHandlers for
I wonder, whether it is possible to create class-methods in VBA. By class-method I
Possible Duplicate: Namespace only class visibility in C#/.NET ? What I want is to
I want to call an overloaded callback method that can accept several different types
I have a messaging function that can be called several times on the same

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.