File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes incompatible types? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "incompatible types?" Watch "incompatible types?" New topic

incompatible types?

kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
public void registrer()
if (antall==nyPerson.length) // sjekke om tabellen er fullt
System.out.println("Tabellen er fullt.");
{ // frithjof
String fornavn = Keyboard.readln("Fornavn: ");
String etternavn = Keyboard.readln("Etternavn: ");
int f�dsels�r = Keyboard.readInt("F�dsels�r: ");

int nr = Keyboard.readInt("Nr: ");
int ans�r = Keyboard.readInt("Ansettelses�r: ");
double l�nn = Keyboard.readDouble("L�nn: ");
double skatteprosent = Keyboard.readDouble("Skatteprosent: ");

Person P = new Person(fornavn, etternavn, f�dsels�r);

nyPerson[antall] = new ArbTaker(P,nr,ans�r, l�nn, skatteprosent);
} // end else
} // end registrer
i get this error message :
---------------------------------- [190:1] incompatible types
found : ArbTaker
required: Person
nyPerson[antall] = new ArbTaker(P,nr,ans�r, l�nn, skatteprosent);
1 error
Errors compiling register.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33119

nyPerson was declared as an array of Person objects. But you are trying to put an ArbTaker object into the array. Unless ArbTaker is a subclass of Person, it won't work.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

a small remark:

It's not a good idea to use local characters in code.
Though it matches the idea of good readable code perfectly, there are some tradeoffs:
If you move your code to a different platform/ environment, it might not work.
Some filesystems might refuse to use local available characters in filenames.
If you have to ask questions in forums, or share the code with foreign developers, they might be unable, to use your code - at least it will make them headaches, how to input these characters on their keyboards.
As far as I know, local characters don't build 'valid', 'allowed' code due to the language specification, though it might work.
kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
Jeanne and Stefan,
thank you for the replies !!
I agree. Here's the link:
subject: incompatible types?
It's not a secret anymore!