How to inheritance a super class without no-argument constructor

i try to inheritance javax.swing.tree.DefaultTreeModel:
public class myTreeModel extends DefaultTreeModel
but the compiler say:
'constructor DefaultTreeModel() not found in class javax.swing.tree.DefaultTreeModel'
and stoped.
How can I get around this?
THANK YOU for your consideration.

Inside myTreeModel, i tried several things:
1. add a no-argument constructor;
Your no argument constructor should be either one of the below :
public myTreeModel() {
   super(new DefaultMutableTreeNode());
public myTreeModel() {
   super(new DefaultMutableTreeNode(), true);
2. add a contructor with (DefaultTreeNode) argument;
Your constructor with tree node argument should be either one of the below :
public myTreeModel(DefaultMutableTreeNode node) {
   super(node);
public myTreeModel(DefaultMutableTreeNode node) {
   super(node, true);
}You would get an error if you did the following:
public myTreeModel() {
public myTreeModel(DefaultMutableTreeNode node) {
}In both of the cases the default no arguement constructor of the super class is called implicitly like:
public myTreeModel() {
   super();
public myTreeModel(DefaultMutableTreeNode node) {
   super();
}In this case the call super() is refering to a no arguement constructor in DefaultTreeModel. However, no such constructor exists in the DefaultTreeModel class resulting in a compile time error.
Note: You do not need to use DefaultMutableTreeNode. You an use some other class that implements the TreeNode interface.

Similar Messages

  • Can defualt inherited the Super Class constructor to sub class ?

    Hi,
    is it passible to inherit the super class constructor by defualt when extends the super class.
    Thanks
    MerlinRoshina

    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • How to reference a class without using the new keyword

    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();

    quedogf94 wrote:
    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();No.
    Using new does not erase anything. There's nothing to erase. It's brand new. It creates a new instance, and whatever that constructor puts in there, is there. If you then change the contents of that instance, and you want to see them, you have to have maintained a reference to it somewhere, and access that instance's state through that reference.
    As already stated, you seem to be confused between class and instance, at the very least.
    Run this. Study the output carefully. Make sure you understand why you see what you do. Then, if you're still confused, try to rephrase your question in a way that makes some sense based on what you've observed.
    (And not that accessing a class (static) member through a reference, like foo1.getNumFoos() is syntactically legal, but is bad form, since it looks like you're accessing an instance (non-static) member. I do it here just for demonstration purposes.)
    public class Foo {
      private static int numFoos; // class variable
      private int x; // instance varaible
      public Foo(int x) {
        this.x = x;
        numFoos++;
      // class method
      public static int getNumFoos() {
        return numFoos;
      // instance method 
      public int getX() {
        return x;
      public static void main (String[] args) {
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ();
        Foo foo1 = new Foo(42);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ();
        Foo foo2 = new Foo(666);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ("foo2.numFoos is " + foo2.getNumFoos ());
        System.out.println ("foo2.x is " + foo2.getX ());
        System.out.println ();
    }

  • Is there any way to access an overridden method of super class?

    class Animals
         void makeNoice(){System.out.println("General noice");}
    class Dog extends Animals
              void makeNoice(){System.out.println("bark");}
    };Is there any way to access the makeNoice() of Animals class from a Dog object
    Dog dog = new Dog();
    Animal animaldog = dog;
    animaldog.makeNoice(); // will always calls Dog's makeNoice() ie the overriden method.
    Is there a way to access the Animals makeNoice() method ? by using cast or super etc?
    Or it is not possible at all?

    Rajeebs wrote:
    Now another question coming in my mind.
    Whether any way to access a method which belong to super class's super class without using any method of class B,
    like super.super.fn() ??Isn't this just the same question again? And won't you again just "solve" it by writing some invokeSuperSuperMethod or other? This flawed design is quickly getting out of hand, isn't it? The question isn't "How can I invoke an arbitrarily deep superclass' method?" but more "Why do I need to invoke a method belonging to a concrete type at all?". If you need to do that, chances are you've misused inheritance.
    To use your initial sample code, in what circumstance would you require that a Dog make anything other than a Dog noise? It makes no sense. Point is, you have an Animal abstraction, and can call makeNoise on any instance of any subclass, and it will make the appropriate noise. By trying to use trickery to force other noises, you're doing something unnatural, and you're also depending on actual specific concrete subclasses. If you're going to go to specific classes and ask them to make their noise, what use is the inheritance? What use it the polymorphism?
    Are we heading into another "I've got a brilliant idea for a [useless language feature|http://forums.sun.com/thread.jspa?threadID=5423706&messageID=10905772#10905772], guys!" thread?

  • Regarding Super classes

    Hi,
    I have created one class in SE24. This class will be used as a super class for other classes.
    When subclasses are derived from this superclass, i want to make sure that some of the methods of superclasses are redefined by the subclasse compulsarily.
    So i want to force the subclasses to redefine complusarily some of the methods of its super class.
    Is this feasible. If so please let me know the corresponding approach.
    Thanks in advance !
    Pramod

    Hi,
    Check this out this will help you.
    Inheritance is the concept of passing the behavior of a class to another class.
    1.You can use an existing class to derive a new class.
    2.Derived class inherits the data and methods of a super class.
    3.However they can overwrite the methods existing methods and also add new once.
    4.Inheritance is to inherit the attributes and methods from a parent class.
    Inheritance:
    Inheritance is the process by which object of one class acquire the properties of another class.
    Advantage of this property is reusability.
    This means we can add additional features to an existing class with out modifying it.
    Go to SE38.
    Provide the program name.
    Provide the properties.
    Save it.
    Provide the logic for inheritance.
    *& Report  ZLOCALCLASS_VARIABLES                      *
    *&----------------------------------------------------*REPORT  ZLOCALCLASS_VARIABLES.
    *OOPS INHERITANCE
    *SUPER CLASS FUNCTIONALITY
    *DEFINE THE CLASS.
    CLASS CL_LC DEFINITION.
    PUBLIC SECTION.
    DATA: A TYPE I,
          B TYPE I,
          C TYPE I.
    METHODS: DISPLAY,
             MM1.
    CLASS-METHODS: MM2.
    ENDCLASS.
    *CLASS IMPLEMENTATION
    CLASS CL_LC IMPLEMENTATION.
    METHOD DISPLAY.
    WRITE:/ 'THIS IS SUPER CLASS' COLOR 7.
    ENDMETHOD.
    METHOD MM1.
    WRITE:/ 'THIS IS MM1 METHOD IN SUPER CLASS'.
    ENDMETHOD.
    METHOD MM2.
    WRITE:/ 'THIS IS THE STATIC METHOD' COLOR 2.
    WRITE:/ 'THIS IS MM2 METHOD IN SUPER CLASS' COLOR 2.
    ENDMETHOD.
    ENDCLASS.
    *SUB CLASS FUNCTIONALITY
    *CREATE THE CLASS.
    *INHERITING THE SUPER CLASS.
    CLASS CL_SUB DEFINITION INHERITING FROM CL_LC. "HOW WE CAN INHERIT
    PUBLIC SECTION.
    DATA: A1 TYPE I,
          B1 TYPE I,
          C1 TYPE I.
    METHODS: DISPLAY REDEFINITION,     "REDEFINE THE SUPER CLASS METHOD
             SUB.
    ENDCLASS.
    *CLASS IMPLEMENTATION.
    CLASS CL_SUB IMPLEMENTATION.
    METHOD DISPLAY.
    WRITE:/ 'THIS IS THE SUB CLASS OVERWRITE METHOD' COLOR 3.
    ENDMETHOD.
    METHOD SUB.
    WRITE:/ 'THIS IS THE SUB CLASS METHOD' COLOR 3.
    ENDMETHOD.
    ENDCLASS.
    *CREATE THE OBJECT FOR SUB CLASS.
    DATA: OBJ TYPE REF TO CL_SUB.
    START-OF-SELECTION.
    CREATE OBJECT OBJ.
    CALL METHOD OBJ->DISPLAY. "THIS IS SUB CLASS METHOD
    CALL METHOD OBJ->SUB.
    WRITE:/'THIS IS THE SUPER CLASS METHODS CALLED BY THE SUB CLASS OBJECT'COLOR 5.
    SKIP 1.
    CALL METHOD OBJ->MM1.     "THIS IS SUPER CLASS METHOD
    CALL METHOD OBJ->MM2.
    *CREATE THE OBJECT FOR SUPER CLASS.
    DATA: OBJ1 TYPE REF TO CL_LC.
    START-OF-SELECTION.
    CREATE OBJECT OBJ1.
    SKIP 3.
    WRITE:/ 'WE CAN CALL ONLY SUPER CLASS METHODS BY USING SUPER CLASS OBJECT' COLOR 5.
    CALL METHOD OBJ1->DISPLAY. "THIS IS SUPER CLASS METHOD
    CALL METHOD OBJ1->MM1.
    CALL METHOD OBJ1->MM2.
    This example will help you to solve your problem.
    For more detailed information GOTO -> SAPTECHNICAL ->Tutorials -> Object Oriented Programming.
    Regards Madhu.
    Code Formatted by: Alvaro Tejada Galindo on Jan 7, 2009 12:13 PM

  • Import class without package

    hellow, i have a web aplication named test , and i have a class named conexion
    when i import a package "pack" with the class conexion, not problem (test/WEB-INF/classes/pack/conexion.class) <% import="pack.* " %> but when i have only the class conexion WITHOUT package (test/WEB-INF/classes/conexion.class) and i import <%import ="conexion" %> i have problem ("The import conexion cannot be resolved") and when i not import the class i have problem (conexion cannot be resolved to a type) , my question is:
    how to i import a class without package in JSP , and if the test/WEB-INF/classes is in the classpath when compile the servlet , why the tomcat not found the class conexion?
    (tomcat 5.5.20 , jdk 1.5.09 , vim)
    thank
    (Sorry my english , i'm from Chile)

    Hi I am hosting my JSP application with Resin 2.17 which uses classes directly in JSP code (not packages). To make this work I had to specify the classpath in Resin.conf and it worked.
    My problem is getting this to work with TomCat or any other application server that will allow me to debug my project in Eclipse or NetBeans IDE. (I have yet to find an IDE that Supports debugging JSP/Java code running on Resin - so I want to switch my application server but I am not sure how to configure my classpath for the application servers to look for java classes in the specified directory just like I did with Resin.

  • Serializing super class

    hi All,
    I was working with object serialization and of the condition is that *"if superclass is not serializable then it must have a public default constructor"*.
    My question is, how will having a default constructor in the super class will help serialization.
    any sort of information in this regard is much appreciated.

    codingMonkey wrote:
    9th-Stallion wrote:
    Thanx for the reply Maaijade.
    The question now is that, if no constructor is available in the super class, won't java will creat a default constructor itself, as it does to creat objects of classes that do not have constructors.
    ThanxOnly if the super class has no other constructors whatsoever.Which, of course, means that after compilation it already has the default constructor anyway, as that is added by the compiler. ;-)

  • How to pass subclass to variable of super class ?

    class /EVUIT/EXCH_PRD_GUI definition
    public section.
      methods CONSTRUCTOR
        importing
          value(I_APPLICATION) type ref to /UIT/EXCH_PRD_APP optional
          value(I_REPID) like SY-REPID .
    class /UIT/EXCH_PRD_VERT_NN_MODEL definition
      public
      inheriting from /EVUIT/EXCH_PRD_APP
      create public .
    DATA: l_vert_nn_model type ref to /uit/exch_prd_vert_nn_model.
    DATA: l_gui type ref to /uit/exch_prd_gui_vbeleg.
       CREATE OBJECT l_vert_nn_model
            EXPORTING
              I_ALV_RECORDS = gt_alv_records[].
    CREATE OBJECT l_gui
       EXPORTING
         I_APPLICATION = l_vert_nn_model
         I_REPID = sy-repid .{color}
    Problem i am facing is for l_gui the parameter i_application is of type super class of l_vert_nn_model.
    Any suggestions, how can i pass this subclass object to the parameter which is of type super class?

    Hello Trivenn
    On SAP basis release 7.00 the following coding works:
    *& Report  ZUS_OO_DUMMY
    REPORT  zus_oo_dummy.
    *       CLASS lcl_local DEFINITION
    CLASS lcl_local DEFINITION.
      PUBLIC SECTION.
        METHODS:
          constructor
            IMPORTING
              value(io_instance)  TYPE REF TO zcl_edi_uk_svcs_out. " super class
      PRIVATE SECTION.
        data: mo_instance         type ref to object.
    ENDCLASS.                    "lcl_local DEFINITION
    *       CLASS lcl_local IMPLEMENTATION
    CLASS lcl_local IMPLEMENTATION.
      METHOD constructor.
        mo_instance ?= io_instance.
      ENDMETHOD.                    "constructor
    ENDCLASS.                    "lcl_local IMPLEMENTATION
    DATA: go_super    TYPE REF TO zcl_edi_uk_svcs_out,
          go_sub      TYPE REF TO zcl_edi_uk_svcs_out_customer,
          go_local    type ref to lcl_local.
    START-OF-SELECTION.
      CREATE OBJECT go_super.
      CREATE OBJECT go_sub.
      create object go_local
        exporting
          io_instance = go_sub.
      BREAK-POINT.
    END-OF-SELECTION.
    Regards
      Uwe

  • How to pass importing parameter of super class method to subclass method?

    hi all,
    i have defined  a class
    CLASS CUST_REPORT DEFINITION.
      PUBLIC SECTION.
        METHODS:DATA_RETRIVE IMPORTING  CUSTID_LOW  TYPE ZCUSTOMER-ZCUSTID
                                       CUSTID_HIGH TYPE ZCUSTOMER-ZCUSTID.
        DATA:IT_CUST TYPE TABLE OF ZCUSTOMER,
             WA_CUST TYPE ZCUSTOMER.
    ENDCLASS.                    "cust_report DEFINITION
    The method DATA_RETRIVE   in this class  has two importing parameters named CUSTID_LOW   and CUSTID_HIGH.
    then i have defined subclas of this clas.
    LASS CUST_ORD DEFINITION INHERITING FROM CUST_REPORT.
      PUBLIC SECTION.
        DATA:IT_ORD TYPE TABLE OF ZORDER.
        METHODS:DATA_RETRIVE  REDEFINITION,
               DISPLAY.
    ENDCLASS.                    "cust_ord DEFINITION
    Method DATA_RETRIVE   is redefined.
    So how to pass importing parameteres of super class method to sub class method with the same name.
    Thanks and Regards,
    Arpita

    Hi,
    I tried like this.
    METHOD DATA_RETRIVE.
    CALL METHOD SUPER->DATA_RETRIVE
          EXPORTING
            CUSTID_LOW  = I_CUSTLOW
            CUSTID_HIGH = I_CUSTHIGH.
    ENDMETHOD.
    But  parameters I_CUSTLOW and I_CUSTHIGH are not getting values after call to method.
    Thanks and Regards,
    Arpita

  • How to get the subclass from a super class( or interface)

    hi,
    I want to get subclass from a super class (or a interface), how to do that? the subclass of a interface means the class implementing the interface.
    for example;
    List ls;
    I want to get the subclass of ls, i.e., LinkedList, Stack, Vector......
    AbstractList al;
    the subclass of al, i.e., ArrayList, Vector.......
    thanks
    Aiwu

    List ls = new ArrayList();Since ls has been declared as a List we can only use List methods
    with it. This is a good thing because we might later want to change
    it to some other sort of List.
    I want to get subclass from a super class (or a interface), how to do
    that?The instance of the subclass declared above did not really come
    from the super class. A class "knows nothing" about its
    subclasses: many sub classes would not even exist at the time
    the class was written.

  • ?Is it possible to create a javafx class without extending Application class ? If yes, how

    Is it possible to create a javafx class without extending Application class ? If yes, how ?

      There is no  such thing as a javafx  class.  It is a regular  java class.  The Aapplication class is  the entry
    point  for JavaFX application.  You have to extend the Application class to create Javafx  application .

  • How to inherit super class constructor in the sub class

    I have a class A and class B
    Class B extends Class A {
    // if i use super i can access the super classs variables and methods
    // But how to inherit super class constructor
    }

    You cannot inherit constructors. You need to define all the ones you need in the subclass. You can then call the corresponding superclass constructor. e.g
    public B() {
        super();
    public B(String name) {
        super(name);
    }

  • How is super class's method called?

    I'm having some doubt about Item 15 in Effective Java, "Design and document for inheritance or else prohibit it".
    The author says if a class is intended to be inherited, then its constructor must not invoke any overridable methods. He gives the following example code. The result of running proves the author's word: The first line is null, and then the second line is a date.
    My question is why Super's constructor calls Sub's version of m, but not its own? Can anyone give me some explanation?
    import java.util.*;
    class Super {
    // Broken - constructor invokes overridable method
        public Super() {
            m();
        public void m() {
    public final class Sub extends Super {
        private final Date date; // Blank final, set by constructor
        Sub() {
            date = new Date();
    // Overrides Super.m, invoked by the constructor Super()
        public void m() {
            System.out.println(date);
        public static void main(String[] args) {
            Sub s = new Sub();
            s.m();
    }

    First up, it's handy (good practice?) to include
    calls to super() in your constructors as an explicit
    reminder as to the order that they'll be executed,
    e.g.
    Sub() {
    super();
    date = new Date();
    }This makes it clear that the superclass's
    constructor will be executed before date is
    initialised.
    Now to your question: a subclass and a superclass
    form a single whole object; the subclass doesn't 'sit
    on top' of the superclass, as it were. Because the
    subclass, Sub, overrides the superclass's
    implementation of method m, its implementation will
    always be invoked. Only Sub.m can call its
    super implementation (i.e. super.m()); So, for
    example, even this would call Sub's implementation of
    method m:Super a = new Sub();
    a.m(); // will invoke Sub.m(), not Super.m()!
    Thank everybody for all the replies.
    Super a = new Sub();
    a.m(); // will invoke Sub.m(), not Super.m()!This is easy to understand. although a is of type Spuer, it's an instance of Sub, so the runtime will decide to invoke Sub's implemention. This is right where Polymorphism comes.
    So it can go a step further, when an instance is being constructed, an instance of Super never exists, and there is only one instance, it's a Sub instance. So, although the m method is invoked by the Super constructor, which version is invoked is chosen by the instance.

  • How to indicate the object of the super Class ?

    hello,
    I need to notify when one dialog is close to the class that generated it.
    Of course I do it from the method windowClosing() in the class WindowAdapter.
    But if I use "this" how parameter in the method, I noted the value is that of the inner anonymous class, and not that of the dialog class.
    I write down some code to reproduce the problem ....
    public ReferenceToTheSuperClass() {
            final SecondClass sc = new SecondClass(this);
            jButton1 = new javax.swing.JButton();
    //        final ReferenceToTheSuperClass xx = this;
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                     sc.checkSuper(xx);                    // work
                     sc.checkSuper(this);                   // not work
                     sc.checkSuper(super.getClass()); // not work
    }  // ReferenceToTheSuperClass
    class SecondClass {
        ReferenceToTheSuperClass superiorClass;
        public SecondClass(ReferenceToTheSuperClass supClass){
            superiorClass = supClass;
        public void checkSuper(Object o){
            if (o instanceof ReferenceToTheSuperClass){
                JOptionPane.showMessageDialog(null,"HELLO");
    } // SecondClass My ask is: It is possible to indicate the value of the instance of the super Class, inside one his anonynimous inner class?
    thank you
    regards
    tonyMrsangelo

    thank you for your kinkly answer jeverd,
    yes what you say is right, in this case the class is only nested (in the hurry I used a wrong word).
    About the sintax, I vould find only a short statement to use inside the inner anomymous class and, reading what you say, I can guess it is not possible to do it..
    again thank you
    regards
    tonyMrsangelo

  • Inherited methods of super class not shown in outline

    Hello, is there a possibility to display the methods and variables from the super class in the outline of the inheriting class in AiE?

    Hi Christian,
    We had discussed this, when we implemented the outline and quick outline some years, ago. Finally, we sticked to the approach that is used by other plug-ins in Eclipse (like JDT).
    There Outline View shows only the content of the current editor. This helps to keep the content of the view stable when you select an element for navigation (because you won't be able to switch the editor by selecting an element ).
    Inherited members are usually part of other editors, unless you have redefined a method in your current class. Therefore, they are not shown in Outline View (unless they are redefinitions).
    The filters like "Hide Non-Public Members of classes" can only hide elements of the current editor.
    Inherited members can be shown in the Quick Outline, because the interaction pattern is different there: If you navigate to an element the pop-up is closed. Therefore, a content change of the Quick-Outline does not hurt.
    Michael

Maybe you are looking for

  • Migration Date when migrating from classic to new g/l

    Hello gurus, I am planning a migration from classic to new g/l, but this fiscal year it will be not possible to finish phase 0 (from migration model plan). Is it possible to do it in the middle of the new fiscal year, what are the withdrawls or issue

  • PO creation error - Info-record

    Hi All, I am trying to create the PO for a particular material,but i am getting an error on saving the PO. "Please contact the responsible person for Info-rec" The Info-record for that material for that vendor is present when i checked in the t-code

  • Process Mapping

    Hi, I'm interested if anyone is spending time, energy and $$ mapping processes in their organization. Some of the presentations at the Primavera Users Conference a couple weeks ago stressed the importance of diagramming processes, and I'm interested

  • Pictures in Posts.

    Hey Everyone! I've noticed that some people put pictures in their posts to clarify what they mean. How are they doing this? When I drag and drop a pic into the text area I get a long piece of text just explaining where it is on my computer. Please He

  • I can't get an extension to work on my E Mail since down loading Lion on my Mac

    every time I try to get an extension to work it disapears since I down loaded Lion