aspose file tools*
The moose likes Beginning Java and the fly likes a little question 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 » Beginning Java
Bookmark "a little question" Watch "a little question" New topic
Author

a little question

peterx peter
Greenhorn

Joined: Nov 02, 2004
Posts: 19
Hi!
This class do nothing but I want to test this code.
Why do I get compile error.
Error after compiling: test.a is not statement
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You can just place a variable like on a line. You have to something with the variable.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
That's because "test.a;" is not a statement. If you are coming from a C background, you know that in C you can turn any expression into a statement by putting a semicolon after it:

x=y; //C and Java syntax

x==y; //C, but not Java, syntax

The trouble with this simple approach to statements is that not all expressions make sensible statements, so Java limits the expression ; syntax to:

; //the empty statement, if that counts

x=y; //assignment

i++;
++i;
i--;
--i; //increment and decrement

x.m(); //method invocation

new X(); //object creation

What you wrote, "test.a;", was just accessing a field, and so not a legitimate statement. Try assigning it or printing it:

int x = test.a;
//or
System.out.println(test.a);


There is no emoticon for what I am feeling!
peterx peter
Greenhorn

Joined: Nov 02, 2004
Posts: 19
Hi Jeff Albertson, Keith Lynn!
Thank you very much for your help.
peter
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok, first off to do test.a, you would have to declare a method 'a'.

Like so:

class test
{
public void a()
{
int integer = 10;
return integer;
}
}

something like that.


You down with OOP? Yeah you know me!
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
*public int a(){}*

sorry, if it returns a int value you have to declare the method of return type int.
R Kharat
Greenhorn

Joined: Apr 07, 2006
Posts: 1
Hi buddy,
Just try putting there a S.O.P statement.
i.e a System.out.println(test.a);
This should display your value.

Thanks!
Rohit.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Monk Fox:
ok, first off to do test.a, you would have to declare a method 'a'.



This is incorrect. "test.a" does NOT refer to a method. It refers to a member variable, which is exactly what the original poster has.

Layne


Java API Documentation
The Java Tutorial
 
Don't get me started about those stupid light bulbs.
 
subject: a little question