• Post Reply Bookmark Topic Watch Topic
  • New Topic

Oracle documentation: placement of statements  RSS feed

 
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a simple question on a statement at Oracle java tutorial - Using Objects. In the beginning of this page, the tutorial mentions "For example, we can add a statement within the Rectangle class that prints the width and height: System.out.println("Width and height are: " + width + ", " + height);". Please refert to this page as well as the page before this one (called Creating objects) for source code of Rectangle.

So far, my understanding is that you can put an executable statment (like System.out.println) only within a method (of Rectangle, or main method). So, the above statement in the tutorial is wrong because it does not make it clear that the println statement should go inside a method, and not outside (alongside class fields). Netbeans IDE throws an error if this statement is outside any method within Rectangle class.
 
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It never says the code is outside a method: it simply says it's inside the Rectangle class.
The point trying to be made is that from within a class, the dot operator doesn't have to be used when accessing fields of the same class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!