aspose file tools*
The moose likes Java in General and the fly likes Object Orientation[Compile Error] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object Orientation[Compile Error]" Watch "Object Orientation[Compile Error]" New topic
Author

Object Orientation[Compile Error]

Isuru Buddhika
Greenhorn

Joined: Nov 04, 2012
Posts: 11

What is the reason for the following programme to give a compile error?

Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1



Class properties (member variables) are declared inside the class (outside methods). So when the compiler get to that line it expects an identifier as the compiler error says.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14272
    
  21

You cannot put arbitrary statements outside methods.

The only thing you can do at class level (outside of a method) is declare variables and optionally initialize them. You cannot put other statements there, such as an assignment statement, which you have in line 4.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11422
    
  16

Isuru Buddhika wrote:What is the reason for the following programme to give a compile error?

Just a little tip...It is often a huge help if when posting questions like this, you include the compiler error you are getting.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
You would also find your code easier to understand yourself if you indented it.
 
jQuery in Action, 2nd edition
 
subject: Object Orientation[Compile Error]