Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

incompatible types?

 
kelvin cheung
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void registrer()
{
if (antall==nyPerson.length) // sjekke om tabellen er fullt
{
System.out.println("Tabellen er fullt.");
}
else
{ // 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);
antall++;
} // end else
} // end registrer
----------------------------------
i get this error message :
----------------------------------
register.java [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
Marshal
Posts: 34372
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne and Stefan,
thank you for the replies !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic