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



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();

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();



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



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();


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.


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


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