Why it wont let me create a object in the main method 13/13

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/learn-java/lessons/object-oriented-programming/exercises/generalizations-oop-java

<In what way does your code behave incorrectly? Include ALL error messages.>
I typed the proper object into the main method " String myOrder = new Coffee(); " but after i run it says "Coffee.java:15: error: incompatible types: Coffee cannot be converted to String
String myOrder = new Coffee();
^
1 error " PLSS HELP ME SOLVE THIS ISSUE

```

class Coffee {

public Coffee() {

}

public void addSugar(int cubes) {

	System.out.println("You added " + cubes + " sugar cubes.");

}

public static void main(String[] args) {

String myOrder = new Coffee();

}

}

<do not remove the three backticks above>

I have the same problem. what even is the main method?

Hey.

Sorry if this reply is too late. But when you create an object of Coffee you need to give the variable myOrder a suitable datatype to go with it. When we create our own classes we’re essentially creating our own user defined data types. Therefore we need to use Coffee instead of a String. And this makes sense because the compile error threw “Coffee cannot be converted to String”. Coffee can not be coverted to a string because Coffee is of type Coffee.

So it should look like this:

Coffee myOrder = new Coffee();
1 Like

The main() method is the very first method called by the java run time environment. It serves as the entry point for the rest of the program so that other methods and various other tasks can be carried out.

1 Like

Thank you angus beef for the help really means a lot that some one helped :smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.