Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSinan the Thinker
7,980 PointsHi 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]
1 Answer
Chase Carnaroli
5,139 PointsI 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.
Trent Christofferson
18,846 PointsTrent Christofferson
18,846 PointsDoes the error give you a line number and what class it is in?