• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Super ref = new Sub();

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Employee implements Printable
{
public void print()
{
System.out.println("inside print");
}

public Employee()
{

}

public static void main(String[] args)
{
Printable p1 =new Employee();
Printable p2 =new Employee();
p1.print();
if(p1.equals(p2))
System.out.println("Equal");
System.out.println("Not Equal");
}
}
how is it possible to call "equals" method on Printable reference??? Because with super class/interface reference we can only call methods of super class/interface .. And "Object" class is not a super class for Printable.
Waiting for a reply...
 
Marshal
Posts: 79654
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Not sure. There is another problem. The print() method in java.awt.print.Printable takes (Graphics, PageFormat) as parameters, and your print() method doesn't take any parameters, so you are overloading the method, not implementing the interface. You can't call print() from a Printable object. Unless you can get a Graphics object and a PageFormat object from somewhere (or dummy objects) you will never get that class to compile.

But when I tried to compile your class, it didn't say anything about equals().
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is explicit language in the Java Language Spec which states that the methods of Object are available on references of interface types.
[ July 06, 2007: Message edited by: Ernest Friedman-Hill ]
 
Campbell Ritchie
Marshal
Posts: 79654
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Mr Friedmann-Hill. That is why my compiler overlooked "equals". I made a mistake; I failed to notice that print needs an int parameter too.
 
pitambari parekh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Mr Friedmann-Hill..
 
pitambari parekh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Mr. Campbell Ritchie .. But one thing i would like to clarify is that by using Printable I meant simply any interface and not specifically the interface from java.awt.print.Printable..
 
Always look on the bright side of life. At least this ad is really tiny:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic