Our code for finding roots by Newton's method has a single class. The program begins with
class Newton {and ends with the closing brace
}
at the end of the file.
All class declarations starts with class
classname {
and end with a }
,
where classname is the name of the class.
The curly braces enclose the "subroutines" and variables associated with
a class. If you look at the example code, you will find inside the
Newton class, there are three "subroutines": main
, f
and fprime
.
Finally, a note about file conventions. Each java code file, such as
Newton.java
, must have a class in it with the same name
as the file. For example, our program with the class Newton
should be saved in a file called Newton.java
.
Next we examine the contents of the Newton class.
![]() |
5.6 Methods: Functions and Subroutines in Java |