[JAVA] Waarom identifier expected bij System.out

Pagina: 1
Acties:
  • 117 views sinds 30-01-2008
  • Reageer

  • Mastermind
  • Registratie: Februari 2000
  • Laatst online: 15-09 23:09
Ik heb een zeer vaag probleem waarbij die om een identifier vraagt terwijl de string gewoon een waarde heeft.
Bij de System.out.println(uitvoer) geeft die: Identifier expected. Maar er staat toch een identifier?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import java.awt.*;
import java.awt.event.*;
import java.io.*;


public class opdracht5

{


private IntAImpl1 impl1=new IntAImpl1("hoi", "hallo", "dag");
private IntAImpl2 impl2=new IntAImpl2("hanze", "jesse", "gerson");
private IntBImpl1 impl3=new IntBImpl1("athlon", "cola", "appeltaart");
private IntBImpl2 impl4=new IntBImpl2("test", "ditis", "opdracht5");

String uitvoer1=impl1.aGeeftString();
String uitvoer2=impl2.aGeeftString();
String uitvoer3=impl3.bGeeftString();
String uitvoer4=impl4.bGeeftString();

System.out.println(uitvoer1);
//Hier geeft die een error^ error Identifier Excpected.
//Wat is de fout?

System.out.println(uitvoer2);
//dit gaat dan ook fout natuurlijk
System.out.println(uitvoer3);
System.out.println(uitvoer4);


public interface IntA 
{
    public String aGeeftString();
}

public interface IntB 
{
    public String bGeeftString();
}

public class IntAImpl1 implements IntA 

{
    private String a,b,c;
    private String uitvoer;
    
    public IntAImpl1 (String a, String b, String c) 
    {
        this.a=a;
        this.b=b;
        this.c=c;
    }
    
    public String aGeeftString()    
    {
        uitvoer=a.toUpperCase();
        return uitvoer;
    }
}   

public class IntAImpl2 implements IntA 
{
    private String a,b,c;
    String uitvoer;
    
    public IntAImpl2 (String a, String b, String c)
    {
        this.a=a;
        this.b=b;
        this.c=c;
    }
    public String aGeeftString()    
    {
     uitvoer=a.toUpperCase();
        return uitvoer;
    }
    
}

public class IntBImpl1 implements IntB 
{
    
    private String a,b,c;
    private String uitvoer;
    public IntBImpl1 (String a, String b, String c)
    {
        this.a=a;
        this.b=b;
        this.c=c;
    }
    
    public String bGeeftString()    
    {
    uitvoer=a.toUpperCase();
        return uitvoer;
    }
    
}   
public class IntBImpl2 implements IntB 
{
    
    private String a,b,c;
    private String uitvoer;
    
    public IntBImpl2 (String a, String b, String c)
    {
        this.a=a;
        this.b=b;
        this.c=c;
    }   
    
    public String bGeeftString()    
    {
    uitvoer=a.toUpperCase();
        return uitvoer;
    }
    
}

}

  • Tsjipmanz
  • Registratie: Oktober 2000
  • Laatst online: 13-05 14:52

Tsjipmanz

Der Rudi ist da

Uhmmm ik ben niet echt een Java-expert (omdat Janoz altijd het toetsenbord jat tijdens practica :) ) maar komt het niet omdat de String uitvoer private is?

There's no such thing as a mistake, just happy accidents - Bob Ross
Relaxte muziek: altijd okee!
- Soulseek rulez -


  • Onno
  • Registratie: Juni 1999
  • Niet online
Uhm.. je moet System.out.println wel binnen een method zetten he, laten we zeggen.. 'main' ofzo. ;)

  • Mastermind
  • Registratie: Februari 2000
  • Laatst online: 15-09 23:09
Op vrijdag 12 oktober 2001 13:36 schreef Onno het volgende:
Uhm.. je moet System.out.println wel binnen een method zetten he, laten we zeggen.. 'main' ofzo. ;)
Ohw! :)

Ik heb nu
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public main()
{
IntAImpl1 impl1=new IntAImpl1("hoi", "hallo", "dag");
IntAImpl2 impl2=new IntAImpl2("hanze", "jesse", "gerson");
IntBImpl1 impl3=new IntBImpl1("athlon", "cola", "appeltaart");
IntBImpl2 impl4=new IntBImpl2("test", "ditis", "opdracht5");

String uitvoer1=impl1.aGeeftString();
String uitvoer2=impl2.aGeeftString();
String uitvoer3=impl3.bGeeftString();
String uitvoer4=impl4.bGeeftString();

System.out.println(uitvoer1);
System.out.println(uitvoer2);
System.out.println(uitvoer3);
System.out.println(uitvoer4);
}

gedaan, maar nu voert die die main niet uit.
Hoe moet dat?

Verwijderd

gedaan, maar nu voert die die main niet uit.
Hoe moet dat?
Verander main() in:
code:
1
public static void main (String args[])

Dit is de methode die de VM als eerste aanroept tijdens de executie. De array args bevat alle command line options.

  • mbravenboer
  • Registratie: Januari 2000
  • Laatst online: 06-11-2025
Misschien een goede idee om eens naar de allereerste tutorials op http://java.sun.com/tutorial te kijken? Neem gewoon even de uitstekende beginners handleidingen daar door. Ze zijn kort, duidelijk en leuk om te doen.

De signature van main methode is toch wel hele erge basis kennis ;)

Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment

Pagina: 1