aspose file tools*
The moose likes Beginning Java and the fly likes i am getting identifier expected error in line 4...      can any one help me out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "i am getting identifier expected error in line 4...      can any one help me out " Watch "i am getting identifier expected error in line 4...      can any one help me out " New topic
Author

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

Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Joined: Jul 06, 2009
Posts: 97
Thanks Cameron McKenzie .
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
ThankYou Cameron Wallace McKenzie.
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 375
Hmm..

Shouldn't it be

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

?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

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

Joined: Aug 05, 2008
Posts: 375
And I thought I had the last word on that one..
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

If it helps you feel any better, you did correct both Cameron and me
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
ya it helps me thaks a lot for both..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i am getting identifier expected error in line 4... can any one help me out