User Tools

Site Tools


java:initializing_classes_and_constructors

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
java:constructor_basics [2020/09/12 05:00] – [Initializing member variables] mithatjava:constructor_basics [2020/09/12 05:02] – [Default constructors] mithat
Line 63: Line 63:
 ===== Default constructors ===== ===== Default constructors =====
  
-Another way to initialize a class is by using a **constructor**: a method that runs automatically whenever you instantiate the object. Constructors are better suited to more complex situations, and they are not limited to just initializing member variables. They can do anything you can normally do in a method. For example, you might want to output that your object was successfully created.+Another way to initialize a class is by using a **constructor**: a method that runs automatically whenever you instantiate the object. Constructors are better suited to more complex situations, and they are not limited to just initializing member variables. You can do anything in a constructor that you can do in a regular method.
  
-A constructor that does does this looks like:+For example, after initializing the state of your object, you might want to output that your object was successfully created. A constructor that does does this looks like:
  
 <code java> <code java>
java/initializing_classes_and_constructors.txt · Last modified: 2020/09/16 18:15 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki