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 Java 8 in Action this week in the Java 8 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: 13884
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10929
    
  12

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: 36599
    
  16
You would also find your code easier to understand yourself if you indented it.
 
 
subject: Object Orientation[Compile Error]
 
Similar Threads
final variables
Inner Class
difference between static local variables and static global variables.
Why it want super class constructor
Operator