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

  2. object - java - can't create a constructor - Stack Overflow

    May 10, 2015 · First define a constructor public Human ( int a ), along with no-args constructor ( if need be ) inside the Human class, only then you can use that inside the main method of …

  3. java - How do I make a constructor that assigns multiple …

    A constructor is a "method-like thing" that has no return type, and the same name as the enclosing class. All you need to do is add some statements that will assign the parameters to …

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

  5. What is the purpose of a no-arg constructor? - Stack Overflow

    In Java, a no-argument constructor is the default constructor and if you don't define explicitly in your program. Then Java Compiler will create a default constructor with no arguments.The …

  6. How to call grandparent constructor with parameters in Java?

    Aug 31, 2015 · 1)When no constructor is supplied to a class, java creates a default non-arg constructor. 2)If a class A extends class B, class B requires a constructor and the …

  7. java - How can I initialize a class without a constructor ... - Stack ...

    @Snhp9 you need to declare the 0-pm constructor in your class before using it. I recommend you implement something akin to the Builder Pattern. It is very versatile. You can read more about …

  8. Best way to handle multiple constructors in Java

    14 You should always construct a valid and legitimate object; and if you can't using constructor parms, you should use a builder object to create one, only releasing the object from the builder …

  9. java create constructor in subclass with superclass as arguments

    Feb 5, 2012 · You'll definitely need to use super to call the superclass constructor - but what arguments you want to use are up to you. We have no idea what the classes are meant to do. …

  10. java - Constructor in an Interface? - Stack Overflow

    An interface does not have an instanced implementation, hence no constructor. The use case you describe is akin to an abstract class in which the constructor calls a method of an abstract …