answersLogoWhite

0


Best Answer

Not as a separate instance. The derived class instance can be used anywhere a superclass instance is expected, so it is an instance of the superclass in that respect, and a superclass constructor will be called at creation time. However, it will always act like an instance of the derived class, even if it is explicitly cast to the superclass. So overridden methods will always call the derived class method, regardless of how an outside caller refers to the instance.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is object of superclass created when object of derived class is created?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is a super class in terms of object oriented programming?

A superclass, also referred to as a parent class, is a class what which other classes are derived from. These derived classes are known as either subclasses or child classes.


What is the Object class parent?

Object is the topmost class in the Java Class hierarchy. There is no Class above Object. All classes in Java are implicitly derived from Object.


What is super class construter?

A superclass constructor is the constructor of the superclass. Constructor is a special method that runs automatically as soon as a method is instantiated (created). Superclass is the class on which a certain class is based. This is what is known as "inheritance" - classes can be based on other classes. This is done as a way of organizing classes, and for code reuse - that is, reducing the amount of duplicate code.


Inheritance vs instantiation in Java?

Inheritance is simply when you get properties and methods from a superclass, whereas instantiation is actually allocating an object in memory based on your class.


In what order are the class constructors called when a derived class object is created?

We know that constructors are invoked at runtime when you say new on some class type as follows: Lamborghini h = new Lamborghini(); But what really happens when you say new Lamborghini() ? (Assume Lamborghini extends Car and Car extends Object.) 1. Lamborghini constructor is invoked. Every constructor invokes the constructor of its superclass with an (implicit) call to super(), 2. Car constructor is invoked (Car is the superclass of Lamborghini). 3. Object constructor is invoked (Object is the ultimate superclass of all classes, so class Car extends Object even though you don't actually type "extends Object" into the Car class declaration. It's implicit.) At this point we're on the top of the hierarchy. 4. Object instance variables are given their explicit values. By explicit values, we mean values that are assigned at the time the variables are declared, like "int x = 27", where "27" is the explicit value (as opposed to the default value) of the instance variable. 5. Object constructor completes. 6. Car instance variables are given their explicit values (if any). 7. Car constructor completes. 8. Lamborghini instance variables are given their explicit values (if any). 9. Lamborghini constructor completes.

Related questions

Give an example of constructor and destructor in derived class?

class superclass { public: superclass() {... } // c'tor public: virtual ~superclass() {... } // d'tor }; // superclass class derived: public superclass { public: derived() : superclass() { ... } // derived c'tor public: virtual ~derived() {... } // derived d'tor }; // derived class


What is a super class in terms of object oriented programming?

A superclass, also referred to as a parent class, is a class what which other classes are derived from. These derived classes are known as either subclasses or child classes.


Which class includes all the others?

The superclass or parent class includes all the other classes. All other classes inherit properties and methods from the superclass.


When a derived class object is deleted which gets deleted first - the base class object or the derived class object?

When there is no further use of derived class obect in execution sequence then It gets deleted. calling of distructor sequence is reverse of constructor calling sequence ,so first derived class obect deleted than base class obect.


What is the Object class parent?

Object is the topmost class in the Java Class hierarchy. There is no Class above Object. All classes in Java are implicitly derived from Object.


What is super class construter?

A superclass constructor is the constructor of the superclass. Constructor is a special method that runs automatically as soon as a method is instantiated (created). Superclass is the class on which a certain class is based. This is what is known as "inheritance" - classes can be based on other classes. This is done as a way of organizing classes, and for code reuse - that is, reducing the amount of duplicate code.


What is C-Sharp equivalent for Java's Object main superclass?

System.object is the base class of all other classes in the .NET framework.


Inheritance vs instantiation in Java?

Inheritance is simply when you get properties and methods from a superclass, whereas instantiation is actually allocating an object in memory based on your class.


What is heritance in java?

With inheritance, you can use methods and fields from the superclass in a subclass. So for example when I have a class Person with fields age and gender, I can make a subclass Student. a Student object has always the fields from its superclass Person (age and gender), but you can make extra fields for a Student object. The same is true for methods: a method defined in the Person class can also be used on a Student object because Student is a subclass from Person. Got it? ;)


In what order are the class constructors called when a derived class object is created?

We know that constructors are invoked at runtime when you say new on some class type as follows: Lamborghini h = new Lamborghini(); But what really happens when you say new Lamborghini() ? (Assume Lamborghini extends Car and Car extends Object.) 1. Lamborghini constructor is invoked. Every constructor invokes the constructor of its superclass with an (implicit) call to super(), 2. Car constructor is invoked (Car is the superclass of Lamborghini). 3. Object constructor is invoked (Object is the ultimate superclass of all classes, so class Car extends Object even though you don't actually type "extends Object" into the Car class declaration. It's implicit.) At this point we're on the top of the hierarchy. 4. Object instance variables are given their explicit values. By explicit values, we mean values that are assigned at the time the variables are declared, like "int x = 27", where "27" is the explicit value (as opposed to the default value) of the instance variable. 5. Object constructor completes. 6. Car instance variables are given their explicit values (if any). 7. Car constructor completes. 8. Lamborghini instance variables are given their explicit values (if any). 9. Lamborghini constructor completes.


What is the Practical application of a derived class object stored in base class pointer?

If you have base class derived object pointing by base class pointer, then you have the power of run time polymorphism in your hand, which gives you the ability to call the derived class implementation of the virtual member function. If we declare the member function as virtual in base class which needs to overridden in derived class, then you can decide at run time which implementation will be called at run time.


.....will be automatically Invoked when an object is created?

The Class object is automatically created by the JVM when an object is created. The Class object provides information about the Class and is primarily used by the IDEs and factory classes. The method that is automatically called when an object is created is called a constructor. In Java, the constructor is a method that has the same name as the class.