• 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

Inner Class Question

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We know that when we implemnt an interface we should implement
all the methods in the interface. It also does in the "inner
class" when we use "inner class" to implemnet the interface or
you will get error message that force you to declare "inner
class" as abstract class.
But, now i was confused by following example
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class AdapterSpot extends Applet //no implements clause
{
private Point clickPoint = null;
private static final int RADIUS = 7;
public void init() {
addMouseListener(new MyMouseAdapter());
}
public void paint(Graphics g) {
g.drawRect(0, 0, getSize().width - 1,
getSize().height - 1);
if (clickPoint != null)
g.fillOval(clickPoint.x-RADIUS,
clickPoint.y-RADIUS,
RADIUS*2, RADIUS*2);
}
class MyMouseAdapter extends MouseAdapter {
public void mousePressed(MouseEvent event) {
clickPoint = event.getPoint();
repaint();
}
}
/* no empty methods! */
}

Question:
Hence, MouseAdapter is an "interface" including five
methods,but, why MyMouseAdapter can ONLY implement mousePressed
mdthod without other methods and work
successfuly???
thax.... ccchang
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MoseAdapter is not an interface. It is an abstract class with no abstract methods.
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CCChang,
Two things:
First, this forum is NOT for real Java Questions. This forum is to discuss JavaRanch itself. Please use the other forums in the future.
Also, please change your name to be compliant with JavaRanch's naming policy.
Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name.
Thanks,
Cindy
 
reply
    Bookmark Topic Watch Topic
  • New Topic