This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Interface doubt

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interface Interface1{
int toString();
}

D:\jdk1.5.0\bin>javac Interface1.java
Interface1.java:2: toString() in Interface1 cannot override toString() in java.l
ang.Object; attempting to use incompatible return type
found : int
required: java.lang.String
int toString();
^
1 error

D:\jdk1.5.0\bin>javap Interface1
Compiled from "Interface1.java"
interface Interface1{
}

Interface1 is not having any relation with Object.
why it is giving compile time error.
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If an interface has no direct superinterfaces, then the interface implicitly declares a public abstract member method m with signature s, return type 'r', and throws clause t corresponding to each public instance method m with signature s, return type 'r', and throws clause t declared in Object, unless a method with the same signature, same return type, and a compatible throws clause is explicitly declared by the interface.
It follows that it is a compile-time error if the interface declares a method with the same signature and different return type or incompatible throws clause.


For more information, please go through this
http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html#32392
 
What are your superhero powers? Go ahead and try them on this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!