answersLogoWhite

0

Constructor Chaining

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.

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

Which situation constructor is used?

Constructor is necessary when you are about to use instance of a class.


When a object is passed to a function as argument why it is not generating an error if the parameterized constructor is defined and not the default constructor?

default constructor is used only when the programmer does not use a constructor to initialize objects. Once the programmer defines a constructor then the default constructor is no longer used


Why you use constructor instead of function?

For every class an empty constructor will be defined automatically by default unless you provide a constructor definition manually. Constructor in a class can be used to initialize variables or perfrom some basic functionallity whenever an object is created.


What is a constructor and its mandatory to use constructor in a class?

A constructor is a method that is invoked when an object is created. As to being mandatory, that really depends on the programming language; in the case of Java, each class must have a constructor, however, in many cases Java will automatically provide a default constructor, so you don't really need to program it.


Default constructor in java?

If you don't type a constructor into your class code, a default constructor will be automatically generated by the compiler. The default constructor is ALWAYS a no-arg constructor. (Obviously the compiler has no clue what all arguments you might want for your class. So it takes the safe way out with a no argument constructor) A no-arg constructor is not necessarily the default (i.e., compiler-supplied) constructor, although the default constructor is always a no-arg constructor. The default constructor is the one the compiler provides! While the default constructor is always a no-arg constructor, you're free to put in your own no-arg constructor.

Related Questions

What is use of constructor in java?

Constructor is used to do something (written in constructor) immediately after object creation.


Why you use constructor overloading?

When we are initializing our object with different internal state then we can use the constructor overloading.


Which situation constructor is used?

Constructor is necessary when you are about to use instance of a class.


When a object is passed to a function as argument why it is not generating an error if the parameterized constructor is defined and not the default constructor?

default constructor is used only when the programmer does not use a constructor to initialize objects. Once the programmer defines a constructor then the default constructor is no longer used


Can somebody give me as much information as possible about chaining Pokemon in Pokemon Diamond and Pearl?

Chaining Pokemon means seeing a Pokemon over and over with the pokeradar. you will know if your chaining if you use the pokeradar appliance in the poketch. if more questions about chaining go to youtube and type in your question!! pokemaster5


Use of constructor?

to create an instance of object


Why constructor use in java?

To create objects of classes


Why you use constructor instead of function?

For every class an empty constructor will be defined automatically by default unless you provide a constructor definition manually. Constructor in a class can be used to initialize variables or perfrom some basic functionallity whenever an object is created.


What is a constructor and its mandatory to use constructor in a class?

A constructor is a method that is invoked when an object is created. As to being mandatory, that really depends on the programming language; in the case of Java, each class must have a constructor, however, in many cases Java will automatically provide a default constructor, so you don't really need to program it.


Default constructor in java?

If you don't type a constructor into your class code, a default constructor will be automatically generated by the compiler. The default constructor is ALWAYS a no-arg constructor. (Obviously the compiler has no clue what all arguments you might want for your class. So it takes the safe way out with a no argument constructor) A no-arg constructor is not necessarily the default (i.e., compiler-supplied) constructor, although the default constructor is always a no-arg constructor. The default constructor is the one the compiler provides! While the default constructor is always a no-arg constructor, you're free to put in your own no-arg constructor.


Why you use constructors?

To create an instance of the class that implementing that constructor


Difference between forward chaining and backward chaining?

Chaining is a teaching technique that consists of breaking a task down into small steps and then teaching each specific step within the sequence by itself. This technique is helpful when students need to learn a routine task that is repetitive. For example, the student may need to learn all of the steps in the process of using the bathroom, putting on a coat or completing a work task.There are two types of chaining techniques: "forward chaining" and "backward chaining."The forward chaining technique moves a student from the first part of the task to the end. The backward chaining technique moves a student from the last part of the task to the beginning. The decision to use either a forward chaining" or backward chaining" is dependent on the student and the task. An analysis of the task and the students ability level will help the teacher decide which chaining procedure is the best method of teaching the task.The chaining technique is part of a larger concept of behavior intervention called applied behavioral analysis. The student is taught a task through the use of the behavioral technique of chaining and then reinforced for completion (click here to see other behavior interventions). In order for the chaining technique to be used appropriately, the task that the student is unable to complete must first be broken down into small steps. The process of breaking those steps down is called "task analysis."