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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:33:00+00:00 2026-05-13T05:33:00+00:00

Please see the code bellow: class A { public x = 5; public y

  • 0

Please see the code bellow:

class A {
    public x = 5;
    public y = 6;
    public z = 7;
}

class B extends A {
    public m = 1;
    public n = 2;
}

$a = new A();
$b = new B()

From the above code let $a is allocating x amount of memory and $b is allocating y amount of memory;

Now my question is which one is correct from bellow?

x > y

x < y

  • 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-13T05:33:00+00:00Added an answer on May 13, 2026 at 5:33 am

    These are my numbers:

    Starting allocation 62480
    Allocated memory for new A() 328
    Allocated memory for new B() 496
    

    Thus x < y

    These two class definitions are equivalent

    class B extends A {
        public $m = 1;
        public $n = 2;
    }
    
    class C {
        public $x = 5;
        public $y = 6;
        public $z = 7;
        public $m = 1;
        public $n = 2;
    }
    

    Meaning that were you to change the definition of B into that of C then the memory usage would be the exact same for using new B() or new C().

    To run it yourself use this code (as an example)

    $start = memory_get_usage();
    echo "Starting allocation $start\n";
    $a = new A();
    $diff = memory_get_usage() - $start;
    echo "Allocated memory for new A() $diff\n";
    $b = new B();
    $diff = memory_get_usage() - $start - $diff;
    echo "Allocated memory for new B() $diff\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see the code bellow: 01. class Test { 02. public function __construct($param1, $param2,
Please see the example code below: class A { private: class B { public:
Please see an example of my code below: CODE UPDATED public class ScrollableCheckboxList {
I am having problems with template class specialization, see the code bellow, please. template
I have problem with session and query execution,please see code below. class A implements
I have problem with session and query execution, please see code below. class A
Please see code below. The destructors are never called. Anyone know why and how
Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
I am using vb.net code. I have grid view, please see the code below:
I am using jquery datepicker, please see below code $(document).ready(function() { $(.txtDate).datepicker({ showOn: 'button',

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.