Witam,
Zostało postawione przede mną proste (wydawałoby się) zadanie: Stwórz klasę.
Otóż stworzyłem taką klasę:
public class Okret {
public static void main(String[] args) {
String typ;
// (...) <--- tu są inne zmienne
public Okret (String a) // <---- tu jest zonk!
{
if (a == "Koga")
{
// (...) <-- tu są zmienne, wszystko jest ok.
}
else if (a == "Bryg")
{
// (...)
}
}
}
}
no i mam następujące zonki:
na początku konstruktora (zonk) Eclipse mówi mi tak:
Multiple markers at this line
- Syntax error on token ")", ; expected
- Syntax error on token "(", . expected
- Okret.String cannot be resolved to a type
- Illegal modifier for parameter a; only final is
WTF ??
dla sprawdzenia stworzyłem pusty konstruktor:
public Okret () {}
A ten uparcie mi wypisuje:
"Multiple markers at this line
- Syntax error on token "}", delete this
token
- Syntax error on token "public", new
expected"
jak zmieniam na
public Okret (int a)
to mi wypisuje:
Multiple markers at this line
- Syntax error, insert ";" to complete Statement
- a cannot be resolved
- Syntax error on token(s), misplaced construct
(s)
- Syntax error on token "int", delete this token
- Okret.String cannot be resolved to a type
- Syntax error on token "(", . expected
- Illegal modifier for parameter a; only final is
permitted
- Syntax error on token ")", ; expected
moje pytania brzmią:
czemu każe mi kasować } ? przecież musze body zamknąć w {}
czemu każe mi zamienić "public" na "new" ? przecież to jest konstruktor a nie obiekt
czemu Okret.String cannot be resolved to a type ? - czy on się odwołuje do body konstruktora ?
Problem nr 2
tą samą klasę wrzuciłem w taką konstrukcję:
public class Zadanie06
{
public static void main(String[] args)
{
class Okret {
// (...) <--- zmienne
String[] typy = new String[5]; // <-- "Syntax error, insert "}" to complete ClassBody"
public Okret(String a) {} // <-- Multiple markers at this line
// - Syntax error on token ")", ; expected
// - Syntax error on token "(", . expected
String getPoziomZagli() // <-- Syntax error on token "String", new expected
{ // <-- Syntax error on token "{", { expected after this token
return poziomZagli;
}
} // <-- Syntax error, insert ";" to complete Statement
}
}
pomożecie mi rozwiązać te zagadki ?
- czy mogę umieścić klasę w klasie ? - czy klasa wewnętrzna musi być wtedy abstrakcyjna ?
- czemy Eclipse zgłasza mi jakieś dziwne żądania dot. kasowania { i ( itp skoro są one konstrukcyjnie poprawne ?
z góry dzięki za wyjaśnienia