Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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
 
You have to be odd to be #1 - Seuss. An odd little ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic