Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile time errors with the program

 
satya narayan reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai iam new to this forum and new to java world too and hope u all will help me out in answering to my queries:

why the below program is giving the comiple time errors:
public class objectDemo
{
objectDemo()
{
System.out.println("iam in the construtor jectDemo()");
}
public Class getClass()
{
System.out.println("returns the class of the object");
}
public int hashCode()
{
System.out.println("returns the hashCode of the object");
}
public boolean equals(Object obj)
{
System.out.println("returns the boolean value of the object");
}
protected void copy(Object src)
{
System.out.println("copies the contents of specified into the current object");
}
public static void main(String args[])
{
objectDemo od = new objectDemo();
od.getClass();
od.hashCode();
od.equals(Object ramu);
od.copy(Object venkat);
}

}
 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the compile time error message say? (I actually know what the error is. However, around here we like to help people learn how to help themselves)
 
satya narayan reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi lancar
this is what the compiler is giving the errors.
so please tell me how to solve this errors

thanks,
reddy

objectDemo.java:28: ')' expected
od.equals(Object ramu);
^
objectDemo.java:29: ')' expected
od.copy(Object venkat);
^
 
Ko Wey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
od.equals(Object ramu);
should be
od.equals(ramu);

the compiler knows already that ramu is something of class Object, so if you remind him, he talks back...
 
satya narayan reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ko Wey,
Thanks for your suggestion but still iam getting comiple time errors as:

objectDemo.java:7: getClass() in objectDemo cannot override getClass() in java.l
ang.Object; overridden method is final
public Class getClass()
^
objectDemo.java:28: cannot resolve symbol
symbol : variable ramu
location: class objectDemo
od.equals(ramu);
^
objectDemo.java:29: cannot resolve symbol
symbol : variable venkat
location: class objectDemo
od.copy(venkat);
^


I can be thankful if anybody fixes these errors

Thanks,
VSNReddy
 
Ko Wey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr. Reddy,

your main could look like this:


Every class you create is a subclass of Object. You inherit the methods of this class Object. Some of these you can "rewrite" (override), some you cannot because they are declared as final. getClass() is final, so you cannot override that method, as the compiler reminds you. So remove that method from your class, recompile and you can than read what the compiler thinks of your class' methods.... (hint: if you declare that your method will return an integer, you are obliged to do just that...)

May I suggest you pick up a good book on java, like (Headfirst java)
http://www.oreilly.com/catalog/hfjava2/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic