User Tools

Site Tools


java:defining_classes_in_java

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:defining_classes_in_java [2020/09/12 02:51] – [Our first Java class] mithatjava:defining_classes_in_java [2020/09/12 02:56] – [Where does the definition go?] mithat
Line 47: Line 47:
 ==== Where does the definition go? ==== ==== Where does the definition go? ====
  
 +=== The easy-for-beginners way ===
 +If there's only one custom class in your program, an easy way to write your program is to incorporate the definition and the program's ''main()'' method.
 +
 +<file java ClickerCounter.java>
 +tbd
 +</file>
 +
 +This isn't generally recommended though because very often you will write more than one custom class in your program.
 +
 +=== The better way ===
  
 In Java, class definitions need to go in their own files, and the files need to be called the name of the class with the ''.java'' extension.((There are certain kinds of classes that don't need to be in their own file, but that's something we can't discuss yet.)) I have deliberately not used any comments in the definition so you can more easily see the code. In Java, class definitions need to go in their own files, and the files need to be called the name of the class with the ''.java'' extension.((There are certain kinds of classes that don't need to be in their own file, but that's something we can't discuss yet.)) I have deliberately not used any comments in the definition so you can more easily see the code.
java/defining_classes_in_java.txt · Last modified: 2020/09/14 01:38 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki