Beginner question referring to an object in a class from within method in that class

Peter Dow <[email protected]> Thu, 27 Jul 2023 15:56:22 -0700
Newsgroups gmane.comp.lang.as400.java
Message-ID <[email protected]>
I'm very much a beginner with Java and I'm having a problem 
understanding how scope works.

In MyPgm below, I get an error saying that fontDetail in the setFont() 
method is undefined.

 From what I've read in the documentation, a reference within the 
setFont() method to a field within the same class but outside the method 
is allowed.

Is fontDetail a field or a variable? Is it only visible within the 
main() method, but not within any methods defined in main()?


public class MyPgm {

   public static void main (String[] parameters) {

     if (parameters.length == 2) {
       String FONTtype    = parameters[0];
       String fontDetailSize = parameters[1];

         wb = new SXSSFWorkbook();
         Font fontDetail = wb.getFontAt((short)0);
         setFont();

     } else {
         System.out.println("Wrong number of parameters.");
         System.exit(1);
     }
     System.exit(0);

     public static void setFont() {
         fontDetail.setFontName(FONTtype); <<=====fontDetail undefined
     }
   }
}

--
*Peter Dow* /
Dow Software Services, Inc.
909 793-9050
[email protected]
[email protected] /
-- 
This is the Java Programming on and around the IBM i (JAVA400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/java400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/java400-l.