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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:16:13+00:00 2026-06-05T06:16:13+00:00

I am extending an existing library (lets call it Lib ) that I cannot

  • 0

I am extending an existing library (lets call it Lib) that I cannot modify directly.

Is there any way to make some methods from Lib private so that they cannot be accessed outside of subclasses?

For example if I have:

class A extends Lib {
    def fun(i: int) = someLibFunction(i) //someLibFunction is inherited from Lib
} 

how can I make someLibFunction private in A, despite it being public/protected in Lib?

  • 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-05T06:16:15+00:00Added an answer on June 5, 2026 at 6:16 am

    This would break the basic foundation of object-oriented programming – that you can use subclass everywhere where super class was expected (polymorphism).

    If it was allowed to narrow down the visibility of a method (e.g. from public to private) client code receiving an instance of Lib would not be allowed to receive A extends Lib. Client code expects someLibFunction() to be accessible and subclass cannot change that contract.

    That being said neither Scala nor any object-oriented language is allowed to narrow down the visibility of any method when subclassing. Note that widening the visibility (e.g. from protected to public is perfectly possible).

    In other words you are not extending an existing API (library). You are creating a completely different API (library) that has a different contract.

    Final example: you have a Vehicle class that has a capacity() and can drive(). Car can extend Vehicle by adding some new capabilities like refuel(). But Container cannot extend Vehicle and hide driving capability. Container can contain Vehicle (or vice-versa), also Container and Vehicle might have common parent like CanHoldCargo.

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

Sidebar

Related Questions

I'm currently extending some existing code that utilizes a lookup table. As it is
Does anyone know of any tools for extending the functionality of Sharepoint's existing version
I'm designing some new class diagrams for extending an existing office automation application. In
I am trying to integrate some pre-existing code that relies on the com.sun.crypto.provider.SunJCE class
I have a project for which we are extending some functionality from an existing
I am extending an existing C++ project. I have a base class that derives
I am extending the existing .NET framework class by deriving it. How do I
Possible Duplicate: extending from two classes I'm currently trying to make a simple Mod
I am looking at extending an existing application through the use of a plugin
What are the best practices for extending an existing Python module – in this

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.