Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't be resolved to a type error

 
roy neela
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following code:
class Animal{}
class Dog extends Animal{
public static void main(String a[])
{
Animal [] ani=(new Animal(), new Dog());
.
.
.
}
}
gives the error "Animal.Dog can't be resolved to a type"
why can't the code execute when it's there in theory!!!
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Use curly braces for array initialization then it should compile fine:



And you hopefully have the Animal and Dog class in two separate files

Marco
[ March 26, 2008: Message edited by: Marco Ehrentreich ]
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marco Ehrentreich:
And you hopefully have the Animal and Dog class in two separate files

Not necessary since they're not both public.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not necessary since they're not both public.


I just wanted to be sure. You never know

Then the curly braces should be your only problem...
 
roy neela
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.... the curly braces solved the problem!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic