Created
January 27, 2024 22:52
-
-
Save m0smith/b42f59f89fe009218687c9c4cba3ded4 to your computer and use it in GitHub Desktop.
First example of a default constructor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bike { | |
int speed; | |
// Notice, no constructor is defined here | |
} | |
public class Main { | |
public static void main(String[] args) { | |
Bike myBike = new Bike(); | |
System.out.println("Speed: " + myBike.speed); // Outputs: Speed: 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment