Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

Hi made a new object with a constant value, tried to check the declared constant value, i got this error;

jshell> pd.MAX_PEZ;
| Error:
| incompatible types: int cannot be converted to Object
| pd.MAX_PEZ;
| ^--------^

My exmaple.java is:

public class Example {

  public static void main(String[] args) {
    // Your amazing code goes here...
    System.out.println("we are makeing a new Object");
    Object object2 = new Object("Sinan");
    System.out.printf("The Name attribute of new object has value %s %n", 
                      object2.getName()
                     );
  }
}   

my Object.java is

class Object {
  public final int MAX_PEZ = 12;
  final private String Name;

  public Object(String Name) {
  this.Name = Name;
  }

  public String getName() {
    return Name;
  }

}

What cou ld be ther error for this? I think to do the same

[MOD: edited code block - srh]

Does the error give you a line number and what class it is in?

1 Answer

Chase Carnaroli
Chase Carnaroli
5,139 Points

I don't think you are allowed to create a class that is called "Object" because it is the superclass of all other classes in Java. Try changing the name of the class to something else (like "Obj" or something, literally anything else) and see if it works.