in Education by
I was just discussing with some colleagues about Java constructors, design-patterns and good way to initialize objects with a unparametrized constructor if I normally await some parameters. One of the older ones came up with his way of implementing always something like: public class Foo { public Foo() { this(0,0,0); } public Foo(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } .. } My question is, is that good style and what is its behaviour exactly? From what I understand should be: it instantiates first an Object and then calling the parametrized constructor to construct a new object of that type with that parameter settings and set its own reference to the new one. So the GC has then to delete the first created one. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
So the GC has then to delete the first created one. No. Only 1 instance is ever created when chaining constructors. To answer your question, yes, it's good style, assuming you need both foo() and foo(int, int, int)

Related questions

0 votes
    Transition effects are available in _group under the animation type options are :a) style; b.Advanced animation ;c )file and d.View Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    Transition effects are available in _group under the animation type options are :a) style; b.Advanced animation ;c )file and d.View Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
0 votes
    What are the best practices if you have a class which accepts some parameters but none of them are allowed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 5, 2022 in Education by JackTerrance
0 votes
    I'm learning Haskell in the hope that it will help me get closer to functional programming. Previously, I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    I have a constructor like as follows: public Agent(){ this.name = "John"; this.id = 9; this. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    I have a constructor like as follows: public Agent(){ this.name = "John"; this.id = 9; this. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    Which of this keyword can be used in a subclass to call the constructor of superclass? (a) super ( ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    The client expects a timely response from the service and might even block while it waits. This represents the _________ client ... B. One to one C. One to many D. Synchronous...
asked Jan 10, 2023 in Technology by JackTerrance
0 votes
    I've extracted certain elements from a HTML page with beautifulsoup and want to extract the according CSS ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 3, 2022 in Education by JackTerrance
0 votes
    I have a style described in Grid.resources. How could I modify height and width(in my sample they ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
...