AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problema banale con codice...

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian)
View previous topic :: View next topic  
Author Message
tranky
Guest





PostPosted: Sun Oct 30, 2005 3:09 pm    Post subject: Problema banale con codice... Reply with quote



avrei bisogno di un aiuto:
ho queste due classi: Main.java e Contatore.java

public class Contatore{
private int val;
public void inc(){val++;}
public void dec(){val--;}
public int view(){return val;}
public void reset(){val=0;}

}

public class Main{
public static void main(String[] args)
{
private int n=10;
int i =0;
Contatore c = new Contatore();
for (i=0;i {
c.inc();
System.out.println(c.view());
}
}

}

perchè se nella classe Main metto private int n=10 mi da questo errore:
illegal start of expression: private int n=10;
mentre se tolgo il private tutto funziona bene?
potreste spiegarmelo a livello teorico?
sono ovviamente un neofita.
grazie tante per l'aiuto già in anticipo.


Back to top
Herbie
Guest





PostPosted: Sun Oct 30, 2005 7:26 pm    Post subject: Re: Problema banale con codice... Reply with quote



On Sun, 30 Oct 2005 16:09:26 +0100, tranky <NOSPAM (AT) GRAZIE (DOT) IT> wrote:
Quote:
public class Main{
public static void main(String[] args)
{
private int n=10;

perchè se nella classe Main metto private int n=10 mi da questo errore:
illegal start of expression: private int n=10;
mentre se tolgo il private tutto funziona bene?

private è un qualificatore per i cmapi della classe, tu lo stai mettendo
dentro un metodo, dove puoi dichiarare variabili ma non membri della
classe come forse volevi fare
Morale, private public e compagnia solo dentro def classe ma fuori dai
metodi

--
Herbie

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.