About 50 results
Open links in new tab
  1. Java Constructors - Stack Overflow

    Aug 21, 2016 · The constructor arguments allow you to provide parameters for the initialization of an object. In this example, you can create a Bicycle object with a gear of 1, cadence of 0, and a speed …

  2. function - Purpose of a constructor in Java? - Stack Overflow

    Nov 13, 2013 · A constructor is used to create an instance of the class Card. And you'll need to call it 52 times to have 52 cards: new Card(1, "hearts"), etc. Now each instance of Player (you also need a …

  3. Java default constructor - Stack Overflow

    Dec 20, 2010 · What exactly is a default constructor — can you tell me which one of the following is a default constructor and what differentiates it from any other constructor? public Module() { this.name …

  4. Methods vs Constructors in Java - Stack Overflow

    Sep 27, 2013 · And you can tell a constructor from other methods because the constructor has the class name for its <method name> and has no declared <return type>. (In Java, of course, you create a …

  5. class - Java Constructors - how to create them - Stack Overflow

    Jul 26, 2020 · In Java, a constructor is a block of codes similar to the method. It is called when an instance of the class is created. At the time of calling constructor, memory for the object is allocated …

  6. Java Record custom constructor - Stack Overflow

    Dec 2, 2021 · import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public record Zoo(List<Animal> animals) { /* * The canonical constructor copies the …

  7. How do I call one constructor from another in Java?

    Nov 13, 2008 · Calling a constructor from another constructor in Java is primarily a means of providing default values for parameters to the one constructor that should actually construct your object, and …

  8. java - Setter methods or constructors - Stack Overflow

    Dec 21, 2016 · There are advantages to this approach as Java beans are supported out of the box in many frameworks like Struts and Spring. A class can also enforce mandatory availability of values by …

  9. class - Java :Setter Getter and constructor - Stack Overflow

    Jul 30, 2013 · My question is that if the constructor is the point of initialization and a default constructor is always present, why use a constructor with parameters to initialize values instead of …

  10. java - Why call super () in a constructor? - Stack Overflow

    May 9, 2012 · 0 as constructor is not a part of class, so while calling it cannot be implemented, by using SUPER () we can call the members and memberfunctions in constructor.