Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i am getting identifier expected error in line 4... can any one help me out

 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package food;
public abstract class Fruit
{
Fruits={"apple","mango","banana"};
}
import food.Fruit;
class Apple extends Fruit
{
public static void main(String args[])
{
System.out.println("apple","mango","banana");
}
}
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Greenhorn! Welcome to the ranch.

Fruit fruits = {}

You didn't declare the type, but just provided a variable name, or so it would appear.

Make sense?

-Cameron McKenzie
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cameron McKenzie .
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cameron Wallace McKenzie wrote:Fruit fruits = {}

Seeing as {} is an array initializer, I would make it an array:


Chandana, please note that you can only use this way of array initializating when you declare the array:
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ThankYou Cameron Wallace McKenzie.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm..

Shouldn't it be

String [] fruits = {"apple","mango","banana"};

?
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ehm. Yes... The array elements are clearly String objects, so the type is quite limited:
- String[]
- Object[]
- Serializable[]
- CharSequence[]
- Comparable<?>[]

Comparable<String>[] will not work.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I thought I had the last word on that one..
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it helps you feel any better, you did correct both Cameron and me
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya it helps me thaks a lot for both..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic