Skip to content

Instantly share code, notes, and snippets.

@m0smith
Created January 27, 2024 22:52
Show Gist options
  • Save m0smith/b42f59f89fe009218687c9c4cba3ded4 to your computer and use it in GitHub Desktop.
Save m0smith/b42f59f89fe009218687c9c4cba3ded4 to your computer and use it in GitHub Desktop.
First example of a default constructor
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