About 5,710,000 results
Open links in new tab
  1. 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 …

  2. 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 …

  3. Java default constructor - Stack Overflow

    Dec 20, 2010 · Java provides a default constructor which takes no arguments and performs no special actions or initializations, when no explicit constructors are provided. The only action …

  4. java - Why do this () and super () have to be the first statement in …

    Jul 23, 2009 · The parent class' constructor needs to be called before the subclass' constructor. This will ensure that if you call any methods on the parent class in your constructor, the parent …

  5. 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 …

  6. Static constructor methods in Java - Stack Overflow

    Feb 7, 2012 · Giving a class static methods that give you more control and gracefulness by returning instances of the class they are in is perfectly acceptable code. This is actually called …

  7. Java: How can a constructor return a value? - Stack Overflow

    A constructor can not return a value because a constructor implicitly returns the reference ID of an object, and since a constructor is also a method and a method can't return more than one values.

  8. java - Should I initialize variable within constructor or outside ...

    Instead of defining and calling a private constructor from all other constructors, you could also define an instance initializer, which will automatically be called before every constructor. That …

  9. java - Why default constructor is required in a parent class if it has ...

    My understanding is that the default constructor is an implicit parameterless constructor. It is only automatically added to a class when no other constructors exist. This would indicate an …

  10. java - Setter methods or constructors - Stack Overflow

    Dec 21, 2016 · So far I have seen two approaches of setting a variable's value in Java. Sometimes a constructor with arguments is used, others setter methods are used to set the …