Abstract method question

Even though the method add in AbstractTest does not throw AnotherException, it compiles fine. Why is it ?
public class AbstractTest extends MyAbstract{
public void add()throws MyException {
class MyException extends Exception {
class AnotherException extends Exception {
abstract class MyAbstract {
abstract public void add() throws MyException, AnotherException;
}

JoachimSauer wrote:
When posting code, please use the code-tags (select your code and press "CODE" just above the text field). It is much easier to read this way.
A method overriding another method is perfectly free to reduce the checked exceptions that it can throw. That's because "throws Foo" only means "I could theoretically throw Foo". It doesn't guarantee that it ever actually throws Foo.
It must not add new ones, however.I like to look at it this way: "throws X" does not mean "I promise to throw X." On the contrary, it means, "I promise +not+ to throw anything +other than+ X (or its subclasses)." So when I child class "narrows" that throws clause it just means that it promises not to throws anything outside of an even smaller subset.

Similar Messages

  • Newbie question about abstract methods

    hey, I'm working on a web application that I was given and I'm a little confused about
    some of the code in some of the classes. These are some methods in this abstract class. I don't understand
    how this post method works if the method it's calling is declared abstract. Could someone please tell me how this works?
        public final Representation post(Representation entity, Variant variant) throws ResourceException {
            prePostAuthorization(entity);
            if (!authorizeGet()) {
                return doUnauthenticatedGet(variant);
            } else {
                return doAuthenticatedPost(entity, variant);
    protected abstract boolean authorizeGet();Thanks
    Edited by: saru88 on Aug 10, 2010 8:09 PM

    Abstract Methods specify the requirements, but to Implement the functionality later.
    So with abstract methods or classes it is possible to seperate the design from the implementation in a software project.
    Abstract methods are always used together with extended classes, so I am pretty sure that you are using another class.
    Btw: Please post the Code Keyword in these brackets:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  • ...is not abstract and does not override abstract method compare

    Why am I getting the above compile error when I am very clearly overriding abstract method compare (ditto abstract method compareTo)? Here is my code -- which was presented 1.5 code and I'm trying to retrofit to 1.4 -- followed by the complete compile time error. Thanks in advance for your help (even though I'm sure this is an easy question for you experts):
    import java.util.*;
       This program sorts a set of item by comparing
       their descriptions.
    public class TreeSetTest
       public static void main(String[] args)
          SortedSet parts = new TreeSet();
          parts.add(new Item("Toaster", 1234));
          parts.add(new Item("Widget", 4562));
          parts.add(new Item("Modem", 9912));
          System.out.println(parts);
          SortedSet sortByDescription = new TreeSet(new
             Comparator()
                public int compare(Item a, Item b)   // LINE CAUSING THE ERROR
                   String descrA = a.getDescription();
                   String descrB = b.getDescription();
                   return descrA.compareTo(descrB);
          sortByDescription.addAll(parts);
          System.out.println(sortByDescription);
       An item with a description and a part number.
    class Item implements Comparable     
          Constructs an item.
          @param aDescription the item's description
          @param aPartNumber the item's part number
       public Item(String aDescription, int aPartNumber)
          description = aDescription;
          partNumber = aPartNumber;
          Gets the description of this item.
          @return the description
       public String getDescription()
          return description;
       public String toString()
          return "[descripion=" + description
             + ", partNumber=" + partNumber + "]";
       public boolean equals(Object otherObject)
          if (this == otherObject) return true;
          if (otherObject == null) return false;
          if (getClass() != otherObject.getClass()) return false;
          Item other = (Item) otherObject;
          return description.equals(other.description)
             && partNumber == other.partNumber;
       public int hashCode()
          return 13 * description.hashCode() + 17 * partNumber;
       public int compareTo(Item other)   // OTHER LINE CAUSING THE ERROR
          return partNumber - other.partNumber;
       private String description;
       private int partNumber;
    }Compiler error:
    TreeSetTest.java:25: <anonymous TreeSetTest$1> is not abstract and does not over
    ride abstract method compare(java.lang.Object,java.lang.Object) in java.util.Com
    parator
                public int compare(Item a, Item b)
                           ^
    TreeSetTest.java:41: Item is not abstract and does not override abstract method
    compareTo(java.lang.Object) in java.lang.Comparable
    class Item implements Comparable
    ^
    2 errors

    According to the book I'm reading, if you merely take
    out the generic from the code, it should compile and
    run in v1.4 (assuming, of course, that the class
    exists in 1.4). I don't know what book you are reading but that's certainly incorrect or incomplete at least. I've manually retrofitted code to 1.4, and you'll be inserting casts as well as replacing type references with Object (or the erased type, to be more precise).
    These interfaces do exist in 1.4, and
    without the generics.Exactly. Which means compareTo takes an Object, and you should change your overriding method accordingly.
    But this raises a new question: how does my 1.4
    compiler know anything about generics? It doesn't and it can't. As the compiler is telling you, those interfaces expect Object. Think about it, you want to implement one interface which declares a method argument type of Object, in several classes, each with a different type. Obviously all of those are not valid overrides.

  • Using an abstract method to assign an annotion property

    Hi Guys
    I have an annotation for specifiying that a method requires a transation. It's very simple, and looks like this:
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    public @interface TransationRequired
        PersistenceUnitDescriptor persistenceUnitDescriptor();
    }PersistenceUnitDescriptor is a simple enum, and I use Aspect J to weave code around methods annotated with this annotation.
    When I annotate a method like this
    @TransationRequired(persistenceUnitDescriptor = PersistenceUnitDescriptor.XXX)
         public Boolean func(String xx)
             //TODO: Something
         }It works fine, but when I annotate like this :
    @TransationRequired(persistenceUnitDescriptor = getPersistenceUnit())
         public Boolean func(String xx)
             //TODO: Something
         }the apect code is never run.
    getPersistenceUnit() is an abstract method and it is the only thing which is different between the two cases.
    I'm not sure if this is beacuse of the annotation or because the weaving, but I thought I would ask in the annotation categroy just in case.
    Anyone got an idea as to what may be causing this?
    Thanks in advance,
    Vackar

    VackarAfzal wrote:
    OK, Thanks for the tip. Pity that it has to be constant, in my opinion annotations would be a lot more powerful if you could dynamically change attributes. That really would make them more than just an alternative to annoying config files. But perhaps there are some technical details that I'm not aware of which makes this idea seem silly.Annotations were designed as a compile-time construct so the values within need to be compile time constants. At runtime, dynamic proxies are used to construct objects whose methods will return the values in question. You are free to construct your own objects implementing the interface of an annotation type at runtime that return values determined more dynamically.

  • Which of the following are true about abstract methods in EJB 2.0

    Hi guys I'm beginner to EJB and i got some unanswered questions.
    Can any one of you please.. give answers?
    Thanks if you do...
    Which of the following are true about abstract methods in EJB 2.0
    CMP?
    Choose all correct answers:
    1. Abstract accessor methods should not be exposed in the EJB
    component's interface
    2.Abstract accessor/mutator methods are used to access and modify
    persistent state and relationship information for entity objects
    3.Abstract Accessor/Mutator methods do not throw exceptions
    4.The EJB developer must implement the Accessor/Mutator methods
    5.Abstract accessor methods may or may not be exposed in the EJB
    component's interface
    2.Which ONE of the following is true?
    Choose the best answer:
    1.Local interfaces cannot have a relationship with other Entity
    components
    2.Local interfaces cannot be used for Stateless Session EJB
    3.Local interfaces can be a part of Object's persistent state
    4.Local interfaces have the same functionality as that of a
    stateless Session EJB
    3.Which of the following describe the <cmr-field> in a EJB 2.0
    descriptor?
    Choose all correct answers:
    1.A Local interface/Entity can be a value of a <cmr-field>
    2.There is no <cmr-field> in EJB 2.0 descriptor
    3.It is used to represent one meaningful association between any
    pair of Entity EJBs, based on the business logic of the Application
    4.It provides a particular mapping from an object model to a
    relational database schema
    5.It allows the Local Entity interfaces to participate in
    relationships
    4.Which of the following are the advantages of using Local interfaces
    instead of dependent value classes?
    Choose all correct answers:
    1.Local Entity Interfaces can participate in Relationships
    2.The life cycle of Local Entity Interfaces is managed by EJB
    container, intelligently
    3.Local Entity Interfaces can be used in EJB QL Queries
    4.Local Entity Interfaces can be a part of the <cmp-field> but not
    <cmr-field>
    5.Which of the following are true about Local interfaces
    1.A local interface must be located in the same JVM to which the EJB
    component is deployed
    2.Local calls involve pass-by-reference.
    3.The objects that are passed as parameters in local interface
    method calls must be serializable.
    4.In general, the references that are passed across the local
    interface cannot be used outside of the immediate call chain and must
    never be stored as part of the state of another enterprise bean.
    6.Which of the following specifies the correct way for a client
    to access a Message driven Bean?
    Choose the best answer:
    1. via a Remote interface
    2. via Home interface
    3. Message driven bean can be accessed directly by the client
    4. both 1 & 2
    5. none of the above
    ------------------------------------------------------------------------7.Which of the following statements are true about message-driven
    bean Clients?
    ------------------------------------------------------------------------Choose all correct answers:
    They can create Queue and QueueConnectionFactory objects
    They can create Topic and TopicConnectionFactory objects
    They can lookup the JNDI server and obtain the references for
    Queue and Topic and their connection Factories
    Only 1 and 2 above

    Hi guys I'm beginner to EJB and i got some unanswered
    questions.
    Can any one of you please.. give answers?
    Thanks if you do...
    Which of the following are true about abstract methods
    in EJB 2.0
    CMP?
    Choose all correct answers:
    1. Abstract accessor methods should not be exposed
    d in the EJB
    component's interfacefalse
    2.Abstract accessor/mutator methods are used to
    access and modify
    persistent state and relationship information for
    entity objectstrue
    >
    3.Abstract Accessor/Mutator methods do not throw
    exceptionstrue
    >
    4.The EJB developer must implement the
    Accessor/Mutator methodsfalse
    5.Abstract accessor methods may or may not be exposed
    in the EJB
    component's interfacetrue
    2.Which ONE of the following is true?
    Choose the best answer:
    1.Local interfaces cannot have a relationship with
    other Entity
    componentsfalse
    2.Local interfaces cannot be used for Stateless
    Session EJBfalse
    3.Local interfaces can be a part of Object's
    persistent statefalse
    4.Local interfaces have the same functionality as
    that of a
    stateless Session EJBtrue
    3.Which of the following describe the <cmr-field> in a
    EJB 2.0
    descriptor?
    Choose all correct answers:
    1.A Local interface/Entity can be a value of a
    <cmr-field>true
    2.There is no <cmr-field> in EJB 2.0 descriptorfalse
    3.It is used to represent one meaningful association
    between any
    pair of Entity EJBs, based on the business logic of
    the Applicationtrue
    4.It provides a particular mapping from an object
    model to a
    relational database schematrue
    5.It allows the Local Entity interfaces to
    participate in
    relationshipstrue
    4.Which of the following are the advantages of using
    Local interfaces
    instead of dependent value classes?
    Choose all correct answers:
    1.Local Entity Interfaces can participate in
    Relationshipsis
    2.The life cycle of Local Entity Interfaces is
    managed by EJB
    container, intelligentlyis
    3.Local Entity Interfaces can be used in EJB QL
    Queriesnot
    4.Local Entity Interfaces can be a part of the
    <cmp-field> but not
    <cmr-field>not
    >
    >
    5.Which of the following are true about Local
    interfaces
    1.A local interface must be located in the same JVM
    M to which the EJB
    component is deployedtrue
    2.Local calls involve pass-by-reference.true
    3.The objects that are passed as parameters in local
    l interface
    method calls must be serializable.false
    4.In general, the references that are passed across
    s the local
    interface cannot be used outside of the immediate
    e call chain and must
    never be stored as part of the state of another
    r enterprise bean.true
    >
    6.Which of the following specifies the correct way for
    a client
    to access a Message driven Bean?
    Choose the best answer:
    1. via a Remote interfacefalse
    2. via Home interfacefalse
    3. Message driven bean can be accessed directly by
    the clientfalse
    4. both 1 & 2false
    5. none of the abovetrue.
    >
    ----------------7.Which of the following statements
    are true about message-driven
    bean Clients?
    ----------------Choose all correct answers:
    They can create Queue and QueueConnectionFactory
    objectsthe container can, dunno bout clients
    >
    They can create Topic and TopicConnectionFactory
    objectsthe container can, dunno bout clients
    >
    They can lookup the JNDI server and obtain the
    references for
    Queue and Topic and their connection Factories
    true
    Only 1 and 2 abovefalse
    somebody correct me if i'm wrong

  • Abstract methods in ByteBuffer class

    I'am a little confused with abstract methods get() and put() in ByteBuffer class.
    Java API says:
    public abstract class ByteBuffer
    extends Buffer implements Comparable
    // This is a partial API listing
    public abstract byte get( );
    public abstract byte get (int index);
    public abstract ByteBuffer put (byte b);
    public abstract ByteBuffer put (int index, byte b);
    }Question is:
    How can I call methods get() and/or put() when they are abstract - not implemented in ByteBuffer class?
    Thanks

    Yeah, it's a subclass of ByteBuffer. You can find out more about the class by using introspection.
    But, you don't have to, to use this API. This is called "design-by-contract" (well, part of it anyway), and that's why the class is hidden with respect to the API docs. The idea is that an API is kind of like a contract, an agreement between the designer and the user of the API. The user of the API is given just what s/he needs to do the job. The designer might implement the API with more stuff that is immediately apparent, but the user doesn't need to know that stuff to use the API. This provides a good layer of abstraction around the API and makes code more flexible.
    So, it's good to know how these things work -- that the ByteBuffer contract is serviced by hidden implementing classes -- but you don't have to know that to use ByteBuffer, and in fact you'd probably only make things difficult (buggy and hard to maintain) if you wrote code that used the fact that apparently the implementing subclass of ByteBuffer is HeapByteBuffer.

  • Superclass and subclass and abstract method

    Hi all,
    I am a little bit confused about abstract methods.
    I define a superclass without abstract keyword and an abstract method inside the superclass. Then I write a subclass to extend the superclass.
    When I compile the source code I get error. It looks like I can't initiate an instance from the supercalss and/or subclass. If I put abstract key word in the superclass definition there is no problem at all. So my question: does abstract method needed to be defined in an abstract superclass only?
    Thank for you input.

    Abstract methods can only be declared in an abstract class.

  • Why java does not force to declare atleast one abstract method

    hi,
    i can define an abstract class without declaring any abstract method in that class. But why wud i do this ? i mean when i have decided that a particular class should be inherited by other subclass and subclass should porvide implementation then there should be atleast one method in the abstract super class which requires implementation.
    All i want to know is why java does not force to declare atleast one abstract method in abstract class.
    there may be some situations where this restriction can create problem if it is like that then can anybody give some example.
    manish

    hi,
    i didn't get u.
    u r trying to say that i have an abstract class with
    only static methods then my questions is why wud
    declare such a class as 'abstract' class? because a
    static method can't be abstract also. Even then if
    somebody want to define such a class with only static
    methods then compiler should force him to declare
    atleast one abstract method which can be implemented
    by subclass, because as i said before if sumbody
    decide to define a class abstract then he wants that
    it should be inhereted but as u r saying a class with
    only static methods then it should not be an abstract
    class it can be a simple class.there's no functional reason, really... actually, factory-like classes are often defined the way Ceci described
    "abstract" only ensures that nobody can ever get an instance of that class (as a matter of fact, what would be the point of getting an instance, if no instance method exists ?)

  • How to find the abstract method?

    Hello all,
    I have a quick question.
    If there is an abstract class with few abstract methods in it, how can we know which one is abstract method in SE24 ?
    Is there any setting to display all the abstract methods in SE24?
    And, all the methods are getting displayed in SE24 in such a way that
    <Interface1>
         method1
         method2
    <Interface2>
         method1
         method2
    Is it possible to display only the methods without its interface name?
    Thank you.
    -Ezhno.

    Hi Ezhno,
    In methods tab of se24, select the method &
    Click on detail view icon i.e. 4th button after Parameter, Exception & code button, there you can see attributes of method , there is a checkbox for 'Abstract'.
    Thanks,
    Sharath

  • Is not abstract and does not override abstract method actionPerformed

    I dont how to corr. Please help!! and thank you very much!!
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class test extends JFrame implements ActionListener, ItemListener
              private CenterPanel centerPanel;
              private QuestionPanel questionPanel;
              private ButtonPanel buttonPanel;
              private ResponsePanel responsePanel;
              private JButton b1,b2,b3,b4,b5;               //Create five references to Jbutton instances
         private JTextField t1,t2,t3,t4,t5;          //Create five references to JTextField instances
              private JLabel label1;                    //Create one references to JLabel instances
              private JRadioButton q1,q2,q3;               //Create three references to JRadioButton instances
              private ButtonGroup radioGroup;               //Create one references to Button Group instances
              private int que1[] = new int[5];           //Create int[4] Array
              private int que2[] = new int[5];
              private int que3[] = new int[5];
              private String temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10,
                        temp11, temp12, temp13, temp14, temp15;
    public test (String header)
              super(header);
              Container container = getContentPane();
              label1 = new JLabel ("PLease click on your response to ");     
              q1 = new JRadioButton("I understand most of the content of this subject",true);
              add(q1);
              q2 = new JRadioButton("I see the relevance of the subject to my degree",false);
              add(q2);
              q3 = new JRadioButton("The workload in this subject is appropriate",false);
              add(q3);
              radioGroup = new ButtonGroup();               //JRadioButton belong to ButtonGroup
              radioGroup.add(q1);
              radioGroup.add(q2);
              radioGroup.add(q3);
              JPanel buttonPanel = new JPanel();
              JPanel responsePanel = new JPanel();
              JPanel questionPanel = new JPanel();
              JPanel centerPanel = new JPanel();
              b1 = new JButton ("Strongly DISAGREE");          //Instantiate JButton with text
              b1.addActionListener (this);               //Register JButtons to receive events
              b2 = new JButton ("DISAGREE");
              b2.addActionListener (this);
              b3 = new JButton ("Neither AGREE or DISAGREE");
              b3.addActionListener (this);
              b4 = new JButton ("AGREE");
              b4.addActionListener (this);
              b5 = new JButton ("Strongly AGREE");
              b5.addActionListener (this);
              buttonPanel.setLayout(new GridLayout(5,1));
              buttonPanel.add(b1);
              buttonPanel.add(b2);
              buttonPanel.add(b3);
              buttonPanel.add(b4);
              buttonPanel.add(b5);
              t1 = new JTextField ("0",3);               //JTextField contains empty string
              t2 = new JTextField ("0",3);
              t3 = new JTextField ("0",3);
              t4 = new JTextField ("0",3);
              t5 = new JTextField ("0",3);
              t1.setEditable( false );
              t2.setEditable( false );
              t3.setEditable( false );
              t4.setEditable( false );
              t5.setEditable( false );
              responsePanel.setLayout(new GridLayout(5,1));
              responsePanel.add(t1);
              responsePanel.add(t2);
              responsePanel.add(t3);
              responsePanel.add(t4);
              responsePanel.add(t5);
              questionPanel.setLayout(new GridLayout(4,1));
              questionPanel.add(label1);
              questionPanel.add(q1);
              questionPanel.add(q2);
              questionPanel.add(q3);
              centerPanel.add(buttonPanel,BorderLayout.CENTER);
              centerPanel.add(responsePanel,BorderLayout.EAST);
              container.add(centerPanel,BorderLayout.WEST);
              container.add(questionPanel,BorderLayout.NORTH);
              q1.addActionListener(
                   new ActionListener(){
              public void actionPerformed( ActionEvent e )          
    {                                        //actionPerformed of all registered listeners
              if (e.getSource() == b1) {
                   que1[0] = Integer.parseInt(t1.getText()) + 1;
                   String temp1 = String.valueOf(que1[0]);
              t1.setText(temp1);
              else if (e.getSource() == b2)     {
                   que1[1] = Integer.parseInt(t2.getText()) + 1;
                   String temp2 = String.valueOf(que1[1]);
              t2.setText(temp2);
              else if (e.getSource() == b3)     {
                   que1[2] = Integer.parseInt(t3.getText()) + 1;
                   String temp3 = String.valueOf(que1[2]);
              t3.setText(temp3);
              else if (e.getSource() == b4)     {
                   que1[3] = Integer.parseInt(t4.getText()) + 1;
                   String temp4 = String.valueOf(que1[3]);
              t4.setText(temp4);
              else if (e.getSource() == b5)     {
                   que1[4] = Integer.parseInt(t5.getText()) + 1;
                   String temp5 = String.valueOf(que1[4]);
              t5.setText(temp5);
    } //end action performed
              q2.addActionListener(
                   new ActionListener(){
              public void actionPerformed( ActionEvent e )          
    {                                        //actionPerformed of all registered listeners
              if (e.getSource() == b1) {
                   que2[0] = Integer.parseInt(t1.getText()) + 1;
                   String temp6 = String.valueOf(que2[0]);
              t1.setText(temp1);
              else if (e.getSource() == b2)     {
                   que2[1] = Integer.parseInt(t2.getText()) + 1;
                   String temp7 = String.valueOf(que2[1]);
              t2.setText(temp7);
              else if (e.getSource() == b3)     {
                   que2[2] = Integer.parseInt(t3.getText()) + 1;
                   String temp8 = String.valueOf(que2[2]);
              t3.setText(temp8);
              else if (e.getSource() == b4)     {
                   que2[3] = Integer.parseInt(t4.getText()) + 1;
                   String temp9 = String.valueOf(que2[3]);
              t4.setText(temp9);
              else if (e.getSource() == b5)     {
                   que2[4] = Integer.parseInt(t5.getText()) + 1;
                   String temp10 = String.valueOf(que2[4]);
              t5.setText(temp10);
    } //end action performed
              q3.addActionListener(
                   new ActionListener(){
              public void actionPerformed( ActionEvent e )          
    {                                        //actionPerformed of all registered listeners
              if (e.getSource() == b1) {
                   que3[0] = Integer.parseInt(t1.getText()) + 1;
                   String temp11 = String.valueOf(que3[0]);
              t1.setText(temp11);
              else if (e.getSource() == b2)     {
                   que3[1] = Integer.parseInt(t2.getText()) + 1;
                   String temp12 = String.valueOf(que3[1]);
              t2.setText(temp12);
              else if (e.getSource() == b3)     {
                   que3[2] = Integer.parseInt(t3.getText()) + 1;
                   String temp13 = String.valueOf(que3[2]);
              t3.setText(temp13);
              else if (e.getSource() == b4)     {
                   que3[3] = Integer.parseInt(t4.getText()) + 1;
                   String temp14 = String.valueOf(que3[3]);
              t4.setText(temp14);
              else if (e.getSource() == b5)     {
                   que3[4] = Integer.parseInt(t5.getText()) + 1;
                   String temp15 = String.valueOf(que3[4]);
              t5.setText(temp15);
    } //end action performed
    }//end constructor test
    public void itemStateChanged(ItemEvent item) {
    //int state = item.getStateChange();
    //if (q1 == item.SELECTED)
              public class ButtonPanel extends JPanel
                   public ButtonPanel()
              public class CenterPanel extends JPanel
                   public CenterPanel()
              public class QuestionPanel extends JPanel
                   public QuestionPanel()
              public class ResponsePanel extends JPanel
                   public ResponsePanel()
    public static void main(String [] args)
         test surveyFrame = new test("Student Survey") ;
         surveyFrame.setSize( 500,300 );
         surveyFrame.setVisible(true);
         surveyFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
         }//end main
    }//end class test

    is not abstract and does not override abstract method actionPerformed
    Oh, I see that the title of your post is an error message? Ok. Well, the test class is declared as implementing an ActionListener. That means the test class must have an actionPerformed() method. Your test class apparently does not.
    It does not appear that the test class needs to implement ActionListener. You are using annonymous classes as listeners.

  • Is not abstract and does not override abstract method tablechanged

    I will remove all the gui code to make it shorter, but my problem lies with my InteractiveTableModelListener.
    public class Meet extends JPanel{
      private static void createAndShowGUI() {
            JFrame frame = new JFrame("MEET_dataTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new Meet(), BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);
    public class InteractiveTableModelListener implements TableModelListener {
         public void TableChanged(TableModelEvent evt) {
      if (evt.getType() == TableModelEvent.UPDATE) {
          int column = evt.getColumn();
          int row = evt.getFirstRow();
          dataTable.setColumnSelectionInterval(column + 1, column + 1);
          dataTable.setRowSelectionInterval(row, row);
    class InteractiveRenderer extends DefaultTableCellRenderer {
      protected int interactiveColumn;
      public InteractiveRenderer(int interactiveColumn) {
          this.interactiveColumn = interactiveColumn;
    public Component getTableCellRendererComponent(JTable dataTable,
         Object value, boolean isSelected, boolean hasFocus, int row,
         int column)
      Component c = super.getTableCellRendererComponent(dataTable, value, isSelected, hasFocus, row, column);
       if (column == interactiveColumn && hasFocus) {
         if ((Meet.this.tableModel.getRowCount() - 1) == row &&
            !Meet.this.tableModel.hasEmptyRow())
             Meet.this.tableModel.addEmptyRow();
        highlightLastRow(row);
      return c;
    public void highlightLastRow(int row) {
         int lastrow = tableModel.getRowCount();
      if (row == lastrow - 1) {
          dataTable.setRowSelectionInterval(lastrow - 1, lastrow - 1);
      else {
          dataTable.setRowSelectionInterval(row + 1, row + 1);
         dataTable.setColumnSelectionInterval(0, 0);
    public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                UIManager.put("swing.boldMetal", Boolean.FALSE);
                createAndShowGUI();
    }As i say, i have removed all the gui code to make it shorter, but in this code i create the table and add all the model to it. I am being returned with the error
    Meet.InteractiveTableModelListener is not abstract and does not override abstract method tableChanged(javax.swing.event.TableModelEvent)in javax.swing.event.TableModelListener
    what would be causing this error?
    Cheers

    Sorry, just figured out my silly error, the method is tableChanged not TableChanged.
    cheers
    TOPIC CLOSED
    Edited by: nick2price on Sep 11, 2008 7:08 AM

  • Is not abstract and does not override abstract method ERROR

    Hello. I'm new at all this, and am attempting to recreate a sample code out of my book (Teach Yourself XML in 24 Hours), and I keep getting an error. I appriciate any help.
    This is the Error that I get:
    DocumentPrinter is not abstract and does not override abstract method skippedEntity(java.lang.String) in org.xml.sax.ContentHandler
    public class DocumentPrinter implements  ContentHandler, ErrorHandler
            ^This is the sourcecode:
    import org.xml.sax.Attributes;
    import org.xml.sax.ContentHandler;
    import org.xml.sax.ErrorHandler;
    import org.xml.sax.Locator;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.XMLReader;
    public class DocumentPrinter implements  ContentHandler, ErrorHandler
    // A Constant containing the name of the SAX parser to use.
    private static final String PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
    public static void main(String[] args)
       // Check to see whether the user supplied any command line arguments.  If not, print an error and exit.
       if (args.length == 0)
         System.out.println("No XML document path specified.");
         System.exit(1);
       // Create a new instance of the DocumentPrinter class.
       DocumentPrinter dp = new DocumentPrinter();
       try
         // Create a new instance of the XML Parser.
         XMLReader parser = (XMLReader)Class.forName(PARSER_NAME).newInstance();
         // Set the parser's content handler
        // parser.setContentHandler(dp);
         // Set the parsers error handler
         parser.setErrorHandler(dp);
         // Parse the file named in the argument
         parser.parse(args[0]);
       catch (Exception ex)
         System.out.println(ex.getMessage());
         ex.printStackTrace();
    public void characters(char[] ch, int start, int length)
       String chars ="";
       for (int i = start; i < start + length; i++)
         chars = chars + ch;
    System.out.println("Recieved characters: " + chars);
    public void startDocument()
    System.out.println("Start Document.");
    public void endDocument()
    System.out.println("End of Document.");
    public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
    System.out.println("Start element: " + localName);
    for (int i = 0; i < atts.getLength(); i++)
    System.out.println(" Attribute: " + atts.getLocalName(i));
    System.out.println(" Value: " + atts.getValue(i));
    public void endElement(String namespaceURI, String localName, String qName)
    System.out.println("End of element: " + localName);
    public void startPrefixMapping(String prefix, String uri)
    System.out.println("Prefix mapping: " + prefix);
    System.out.println("URI: " + uri);
    public void endPrefixMapping(String prefix)
    System.out.println("End of prefix mapping: " + prefix);
    public void ignorableWhitespace(char[] ch, int start, int length)
    System.out.println("Recieved whitespace.");
    public void processingInstruction(String target, String data)
    System.out.println("Recieved processing instruction:");
    System.out.println("Target: " + target);
    System.out.println("Data: " + data);
    public void setDocumentLocation(Locator locator)
    // Nada
    public void error(SAXParseException exception)
    System.out.println("Parsing error on line " + exception.getLineNumber());
    public void fatalError(SAXParseException exception)
    System.out.println("Fatal parsing error on line " + exception.getLineNumber());
    public void warning(SAXParseException exception)
    System.out.println("Warning on line " + exception.getLineNumber());

    Check to make sure that the arguments are consistent with your ContentHandler class. Probably the wrong type.
    I think you forgot to include the skippedEntity method, it seems to be missing. Even if an implemented class has a method that you are not using, you still have to include the method in your code even if it doesn't do anything.
    Message was edited by:
    ChargersTule1

  • Product is not abstract and does not override abstract method

    Received the following errors.
    Product.java:3: Product is not abstract and does not override abstract method ge
    tDisplayText() in Displayable
    public class Product implements Displayable
    ^
    Product.java:16: getDisplayText() in Product cannot implement getDisplayText() i
    n Displayable; attempting to use incompatible return type
    found : void
    required: java.lang.String
    public void getDisplayText()
    ^
    2 errors
    Code reads as follows
    import java.text.NumberFormat;
    public class Product implements Displayable
         private String code;
         private String description;
         private double price;
         public Product()
              this.code = "";
              this.description = "";
              this.price = 0;
    public void getDisplayText()
    String message =
    "Code: " + code + "\n" +
    "Description: " + description + "\n" +
    "Price: " + this.getFormattedPrice() + "\n";
         public Product(String code, String description, double price)
              this.code = code;
              this.description = description;
              this.price = price;
         public void setCode(String code)
              this.code = code;
         public String getCode(){
              return code;
         public void setDescription(String description)
              this.description = description;
         public String getDescription()
              return description;
         public void setPrice(double price)
              this.price = price;
         public double getPrice()
              return price;
         public String getFormattedPrice()
              NumberFormat currency = NumberFormat.getCurrencyInstance();
              return currency.format(price);
    Please help!

    Received the following errors.
    Product.java:3: Product is not abstract and does not
    override abstract method ge
    tDisplayText() in Displayable
    public class Product implements Displayable
    ^
    Product.java:16: getDisplayText() in Product cannot
    implement getDisplayText() i
    n Displayable; attempting to use incompatible return
    type
    found : void
    required: java.lang.String
    public void getDisplayText()
    ^
    2 errors
    Code reads as follows
    Please use the code tags when posting code. There is a code button right above the text box where you enter your post. Click on it and put the code between the code tags.
    These error messages are quite clear in telling what is wrong. You have an Interface called Displayable that specifies a method something like thispublic String getDisplayText() {But in your Product source code, you created thismethodpublic void getDisplayText() {The compiler is complaining because the methods are not the same.
    You also need to return a String in the method probalby like thisreturn message;

  • Getting error while creating abstract method

    hi folks,
    i facing issue for ABSTRACT Class.
    I am trying to create abstarct method, (refered example from saptechnical site),
    I created one attribute i-num, created one method AREA, in  implementation area , i made it as Abstract, then i did syntax check, then it is giving below error.
    *Class ZTEST_CLASS01_AB,Method AREA
    The abstract method "AREA" can only be implemented after its
    redefinition (METHODS AREA REDEFINITION).*
    i tried all the ways..
    created subclass for this, i writted some code in AREA of Sub-class, there it is giving dump, because first one is not activated properly..
    could you please somebody help me on this.
    Sri

    Hello Arshad,
    Create a class(ZABSTRACT) and make its type as Abstract( Which means atleast one of its methods is abstract)
    We can have abstract classes with all it's methods as non-abstract or concrete. A small example is given below:
    CLASS gcl_abstract DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS concrete. "Concrete
    ENDCLASS.                    "gcl_abstract DEFINITION
    *       CLASS gcl_abstract IMPLEMENTATION
    CLASS gcl_abstract IMPLEMENTATION.
      METHOD concrete.
        WRITE: / `I'm a concrete method`.
      ENDMETHOD.                    "concrete
    ENDCLASS.                    "gcl_abstract IMPLEMENTATION
    *       CLASS gcl_abstract_sub DEFINITION
    CLASS gcl_abstract_sub DEFINITION INHERITING FROM gcl_abstract.
      PUBLIC SECTION.
        METHODS concrete REDEFINITION.
    ENDCLASS.                    "gcl_abstract_sub DEFINITION
    *       CLASS gcl_abstract_sub IMPLEMENTATION
    CLASS gcl_abstract_sub IMPLEMENTATION.
      METHOD concrete.
        super->concrete( ).
        WRITE: / 'Abstract class might not have abstract methods at all!'.
      ENDMETHOD.                    "concrete
    ENDCLASS.                    "gcl_abstract_sub IMPLEMENTATION
    START-OF-SELECTION.
      DATA: go_abstract TYPE REF TO gcl_abstract_sub.
      CREATE OBJECT go_abstract.
      go_abstract->concrete( ).
    Although i will agree there is no point in making a class as abstract & having no abstract method
    @Sri: Looks like you're trying to implement the abstract method "AREA" in the abstract class hence the error. For abstract method you cannot define their implementation in the corres. abstract class.
    BR,
    Suhas
    Edited by: Suhas Saha on Mar 30, 2011 12:04 PM

  • Abstract method called in an abstract class

    Hello,
    I am writing some code that I'd like to be as generic as possible.
    I created an abstract class called Chromozome. This abstract class has a protected abstract method called initialize().
    I also created an abstract class called Algorithm which contains a protected ArrayList<Chromozome>.
    I would like to create a non abstract method (called initializePopulation()) which would create instances of Chromozome, call their method initialize() and full the ArrayList with them.
    In a practical matter, only subclass of Algorithm will be used, using an ArrayList of a subclass of Chromozome implementing their own version of initialize.
    I have been thinking of that and concluded it was impossible to do. But I'd like to ask more talented peaple before forgetting it !
    Thanks,
    Vincent

    Ok, let's it is not impossible, juste that I had no idea of how doing it :-)
    The difficulty is that Algorithm will never have to deal with Chromozome itself, but always with subclass of Chromozome. This is usually not an issue, but in that case, Algorithm is required to create instances of the desired subclass of Chromozome, but without knowing in advance wich subclass will be used (I hope what I say makes any sense).
    Actually I may have found a way in the meantime, but maybe not the best one.
    I created in Algorithm an abstract method :
    protected abstract Chromozome createChromozome()The method initializePopulation will call createChromozome instead of calling directly the constructor and the initialize() method of Chromozome.
    Then subclass of Algorithm will implement the method createChromozome using the desired subclass of Chromozome.

Maybe you are looking for

  • How do I connect my mid-2009 Macbook pro to my HDMI television and get sound?

    How do I connect my mid-2009 Macbook pro to my HDMI television and get sound?

  • Any setting required in SLD for EDI,XI,Seeburger Implementation.

    hi, what we need to do in SLD to implement EDI using seeburger adapter,do we need to install SWCV and create TS and BS like we do in general? or we create ,in Integration Directory,party and then Business service (or Business System) and CC? thank yo

  • How to set the source property of image control dynamically?

    Hi,   I have different fxg files which I want to display in a list. For each row in the List, I define which fxg file to be displayed in my database. I need to know how to set the image1.source = (the fxg path) as a string from database? Is there any

  • Select..... from table...... having max date

    I'm trying to select the row from a table that has the maximum date. For example, lets say I want the name of the most recently created object in dba_objects. I can do this using a sub-query, but surely there must be an easier way, and querying this

  • Domain - single value range

    HI, Ive created an enumarated domain. I want to print a report based on this table, how can i print the description depeneding on value. For e,.g the domain zcusttype contains following allowed values 01- Internal 02 - external How can i pick the dec