About 353,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 also need a …

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

  3. Java default constructor - Stack Overflow

    Dec 20, 2010 · To make it explicite: if you write your own constructor, java will not create the default constructur. So if you need a constructor with arguments and a constructor without arguments (like …

  4. java - Can a class have no constructor? - Stack Overflow

    Dec 8, 2012 · Java does not actually require an explicit constructor in the class description. If you do not include a constructor, then the Java compiler will create a default constructor with an empty argument.

  5. java - Creating an instance using the class name and calling ...

    Is there a way to create an instance of a particular class given the class name (dynamic) and pass parameters to its constructor. Something like: Object object = createInstance("mypackage.MyClass","

  6. How to define custom exception class in Java, the easiest way?

    Sep 23, 2010 · 62 If you use the new class dialog in Eclipse you can just set the Superclass field to java.lang.Exception and check "Constructors from superclass" and it will generate the following:

  7. Can a constructor in Java be private? - Stack Overflow

    May 12, 2010 · overloaded constructors - as a result of overloading methods and constructors, some may be private and some public. Especially in case when there is a non-public class that you use in …

  8. java - How do I fast generate constructor and getter, setter in visual ...

    Sep 11, 2023 · In Netbean, I can just use Ctrl + Space to fast generate Constructor, or right click and select insert code to get Constructor and Getter and Setter. How do you do that in VS Code?

  9. java - Can an abstract class have a constructor? - Stack Overflow

    Nov 4, 2008 · The same case applies to abstract classes. Though we cannot create an object of an abstract class, when we create an object of a class which is concrete and subclass of the abstract …

  10. java - how to inherit Constructor from super class to sub class - Stack ...

    Oct 2, 2012 · You simply pass the arguments up the constructor chain, like method calls to super classes, but using super (...) which references the super-class constructor and passes in the given args.