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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:59:54+00:00 2026-05-16T01:59:54+00:00

Consider the following inheritance example: class A {…} class B extends A { ..

  • 0

Consider the following inheritance example:

class A {...}  
class B extends A  
{  
 ..  
 ..  
 private static void main(String[] s)  
 {  
    A a1 = new A();  
    B b1 = new B();  
    B b2 = b1;             // What if it was B b2 = new B(); b2 = b1;  
 }
}

My question is in the comment. Would it be different, in the sense that, using the new operator creates a new space for the object b2 and b2=b1 would just copy the data of b1 into b2. So any changes done to one object won’t affect the other. In the main inline code, B b2 = b1 would point b2 to the space allocated for b1. So any changes here would affect both the object data.

My query is, will using the new operator make any difference to the object manipulation?

  • 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-16T01:59:55+00:00Added an answer on May 16, 2026 at 1:59 am
    B b1 = new B();
    B b2 = b1;
    

    Above code creates only one object of type B. b1 and b2 are references that point to that same object. They are aliases to the same object.

    B b1 = new B(); //1
    B b2 = new B(); //2
    b2 = b1;        //3
    

    In this code, two objects of type B are created at lines 1 and 2. However, after line 3, b2 references the same object as b1 and both are thus again aliases. The object originally referenced by b2 now becomes eligible for garbage collection.

    So, in both cases, b1 and b2 point to the same object and any changes done to that object will be seen through both the references. Keep in mind that b1 and b2 are not the object themselves but only references to that object. b1=b2 doesn’t copy any values from one object to the other, it simply repoints the reference.

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

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The .NET framework has a built-in licensing model (MSDN). See… May 16, 2026 at 11:12 pm
  • Editorial Team
    Editorial Team added an answer Use DatabaseMetaData to get the table information. You can use… May 16, 2026 at 11:12 pm
  • Editorial Team
    Editorial Team added an answer Just guessing - maybe p.content.gsub! pattern, " ".html_safe may help? May 16, 2026 at 11:12 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Consider the following inheritance: abstract class Employee { private string empID; private string empName;
Consider the following Java exception classes: public class BarException extends RuntimeException { // [...]
Consider the following Scala case class: case class WideLoad(a: String, b: Int, c: Float,
I have a problem with Visual Studio 2008 concerning virtual inheritance. Consider the following
Consider the following class hierarchy: base class Object with a virtual method foo() an
Consider that i have two entities with following relationship: Entity A <-->> Entity B
Given the following inheritance tree, what would be the best way of implementing it
I don't necessarily see a grandiose benefit of interfaces inheriting interfaces. Consider the following
Consider following snippet code for xml. <rootnode> <child id=child1 ><![CDATA[child 1]]></child> <child id=child2 ><![CDATA[child
Consider following array $details = array( array('lname'=>'A', 'fname'=>'P','membkey'=>700,'head'=>'y'), array('lname'=>'B', 'fname'=>'Q','membkey'=>540,'head'=>'n'), array('lname'=>'C', 'fname'=>'R','membkey'=>700,'head'=>'n'), array('lname'=>'D', 'fname'=>'S','membkey'=>540,'head'=>'y'),

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.