hopefully its easy.

in main class I have got method from proff

private class AddBBQChips implements ActionListener
	{
		public void actionPerformed(ActionEvent ae)
		{
			addChips( BagOfChips.Flavor.BBQ );
		}
	}

private void addChips(final BagOfChips.Flavor flavor){
    BagOfChips bag = new BagOfChips( flavor );
    System.out.println(bag.toString());
}

and from my class "BagofChips"

public String name;
	
	BagOfChips(String flavor){
		name= flavor;
	}
            public String toString(){
		return name;
	}

of course, it does not run. What's wrong with it?
I can only modify the second one.

Recommended Answers

All 3 Replies

The first class tries to call a BagOfChips constructor with a parameter of type BagOfChips.Flavor, but you only have a constructor that takes a String.

whats the type of Flavor?

Is it class it self? if so should i define in BagOfChips class?

public class BagOfChips {
	public static class Flavor {
		
		public static final  Flavor BBQ = null ;
	
	}

	private Flavor type;

	
	public BagOfChips(Flavor flavor){
		type = flavor;
		
	}
	
	public String toString(){
		return type.toString();
	}

The syntax BagOfChips.Flavor.BBQ implies that Flavor is a public member of the BagOfChips class, and BBQ is a public member of Flavor. I can't tell whether iBagOfChips is a class or an enum, but if you haven't done enums yet, it's probably intended to be a class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.