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

  • Home
  • SEARCH
  • 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 9137741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:09:54+00:00 2026-06-17T09:09:54+00:00

class Bar{ public function test(){ $this->testPublic(); $this->testPrivate(); } public function testPublic(){ echo Bar::testPublic\n; }

  • 0
class Bar{        
    public function test(){
        $this->testPublic();
        $this->testPrivate();
    }

    public function testPublic(){
        echo "Bar::testPublic\n";
    }

    private function testPrivate(){
        echo "Bar::testPrivate\n";
    }        
}

class Foo extends Bar{
    public function testPublic(){
        echo "Foo::testPublic\n";
    }
    private function testPrivate(){
        echo "Foo::testPrivate\n";
    }

}

$myFoo = new Foo();
$myFoo->test();
//Foo::testPublic
//Bar::testPrivate

I’m having a lot of trouble understanding this output. Would someone be able to give me a clear succinct explanation of what is going on? I’m learning OOP and wanted to know how to use extensions to override the parent class functions.

  • 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-17T09:09:55+00:00Added an answer on June 17, 2026 at 9:09 am

    The test() method calls 2 methods:

    1. testPublic – it’s a public one, so it was overriden in the Foo. So the Foo::testPublic is called
    2. testPrivate – it’s a private one, so it’s only visible for each class itself. For the caller method (it’s Bar) – it’s a Bar::testPrivate

    So – if the method is public or protected – it can be overriden and called from the ancestor/child; if it’s private – it cannot.

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

Sidebar

Related Questions

Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*
I'm just learning unit testing. This php code class Foo { public function bar($arg)
class a { public function f(&$ref1, &$ref2) { $ref1 = 'foo'; $ref2 = 'bar';
Foo.java public class Foo{ public int i = 0; } Bar.scala class Bar() extends
With an example class such as this: class Test{ public function &__get($name){ print_r($name); }
Please take a look at this code: class Foo { public $barInstance; public function
class Interface{}; class Foo: public Interface{}; class Bar{ public: vector<Interface*> getStuff(); private: vector<Foo*> stuff;
Quick question regarding __callStatic() in PHP; class Test{ public static function __callStatic($method, $arguments){ echo
This does work: $test = new Test(); $test->blah(); class Test // extends DateInterval {
Suppose I have: class Foo { ... }; class Bar : public Foo {

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.