Solved

EASY - silly question from a beginner...

Posted on 2006-07-08
4
199 Views
Last Modified: 2010-03-31
////////////////////////////////////////////////////
public class welcome {

      /**
       * @param args
       */
      public static void main(String[] args) {
            String strOne = "this is a string";
            
            int intOne = NumberOfBytes(strOne);
            System.out.println(strOne);
            System.out.println(intOne);
      }

}
class NumberOfBytes{
      int storage (String s){
            return s.length() * 2;
      }
}

////////////////////////////////////////////////////////
says:
the method NumberOfBytes(String) is undefined for the method welcome

why?
0
Comment
Question by:Wibble_
  • 3
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17064816
Change

>>class NumberOfBytes{

to

static class NumberOfBytes{

and

>>int intOne = NumberOfBytes(strOne);

to

int intOne = NumberOfBytes.storage(strOne);
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 17064825
Two more things:

1. move your second '}' right to the end of the file
2. change

>>int storage (String s){

to

static int storage (String s){
0
 

Author Comment

by:Wibble_
ID: 17064909
////////////////////////////////////////////////////
public class welcome {

     /**
      * @param args
      */
     public static void main(String[] args) {
          String strOne = "this is a string";
         
          int intOne = NumberOfBytes.storage(strOne);
          System.out.println(strOne);
          System.out.println(intOne);
     }


static class NumberOfBytes{
     static int storage (String s){
          return s.length() * 2;
     }
}
}
/////////////////////////////////////////////


Hurrah! Thank you CEHJ. It needs to be static, because otherwise it doesn't exist...

yay.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17065174
:-)
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 85
mockito example issue 8 73
thymeleaf natural templating vs JSP 2 104
ForLoop Example 3 49
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question