This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Compile time errors with the program

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}

}
 
Sheriff
Posts: 16767
281
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
^
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/
reply
    Bookmark Topic Watch Topic
  • New Topic