• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

super classes and interfaces

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everybody,
abstract class Super
{
abstract void shape();
}
interface Design
{
void shape();
}
class Sub extends Super implements Design
{
//which shape() needs to be given implementation
}
getting
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my version:
<pre>
abstract class Super
{
abstract void shape();
}
interface Design
{
void shape();
}
class Subclass extends Super implements Design
{
//which shape() needs to be given implementation
public void shape ()
{
System.out.println ("I am the overrided shape");
}
public static void main (String args [])
{
Super shape1 = new Subclass ();
shape1.shape ();
Design shape2 = new Subclass ();
shape2.shape ();
}
}
</pre>
It doesn't matter what shape() it is as long as both of them having the same signature in Super and Design. When you implement the shape () method in a subclass you are actually overriding the one in both Super and Design.
One thing to watch is all methods declared in an interface are implicitly declare public. That's why I have to declare "public void shape ()" in the subclass. Without the public modifier, the java compiler will complain.
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That one
I don't have time to test (I already passed Certification) but I'm sure you have the time if you're still studying
From what I remember reading is that since both methods have the same signature, one implementation will satisfy both at the same time... Your mileage may vary...
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the return type of the 2 methods with the same name would have been different, then the compiler is confused and yells at us. . Because it does not know which method, the subclass could possibly implement. You can't have 2 methods with same signature and different return types in the same class right?
regds
maha anna
[This message has been edited by maha anna (edited May 01, 2000).]
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic