Can we chagne Super class method parameters in Sub class

Hi,
I created a super class.  In that class i created a method. That method is having 4 input parameters and 4 export parameters.
I created a sub class for that super class. I need to use only 2 input parameters in this class rather than 4 parameters. I want to delete 2 Input parameters in the sub class of the super class method.  Is it possible.
If possible. can we give an simple code or pseudo code?
regards,
krishna

Hi,
I think you can not.
Because, only public attributes can be inherited and they will remain public in the subclass.
for further detail check,
http://help.sap.com/saphelp_nw70/helpdata/en/1d/df5f57127111d3b9390000e8353423/content.htm
regards,
Anirban

Similar Messages

  • Can we call super class method from Overwrite method using SUPER keyword

    Hi All,
    For one of our requirement , I need to overwrite "Process Event" method of a feeder class  ,where process event is present is protected method. so when we are making a call , then its saying
    "Method  "process event"  is unknown or Protected  or PRIVATE ".
        But we are just copied the source code in the "Process Event" method to the Overwrite method.
    Can anyone provide me the clarification , why system behaving like this.
    Thanks
    Channa

    Hi,
    I think you can not.
    Because, only public attributes can be inherited and they will remain public in the subclass.
    for further detail check,
    http://help.sap.com/saphelp_nw70/helpdata/en/1d/df5f57127111d3b9390000e8353423/content.htm
    regards,
    Anirban

  • Can one method  import parameters can be added in another method parameters

    hello all,
    I am using a BADI   WORKORDER_UPDATE  in which In_update method is there with certain import parameters.
    I want some of those parameters in another method named at_release of same BADI .
    Those import parameters are not there in at_release. They are only in Import of in_update.
    I have actually created an Implementation of the BADI.
    I dont know how to do that please let me know.
    Thanks in advance.

    Hello Sonal
    The solution for your problem is quite simple:
    Define all required IMPORTING parameters of IN_UPDATE as instance attributes of your class, e.g.:
    MT_HEADER    TYPE cobai_t_header.
    Within method IN_UPDATE store the required IMPORTING parameters, e.g.:
    METHOD IF_EX_WORKORDER_UPDATE~IN_UPDATE.
      me->mt_header = it_header.
    ENDMETHOD.
    Within method AT_RELEASE you can access the header data like this:
    LOOP AT me->mt_header INTO ...
    ENDLOOP.
    Regards
      Uwe

  • Inner classes can't access parent classes in constructor

    I'm having a problem where I have class A, which has an Inner class B, which has it's own inner class C. In C's constructor (the inner most class), i'm trying to access a method of A (the top most class), and I get a NullPointerException with trace:
    at mearns.finance.DefaultPortfolio.access$0(DefaultPortfolio.java:1)
    at mearns.finance.DefaultPortfolio$AccountsEditor$AccountsTableModel.<init>(DefaultPortfolio.java:253)
    In this case "DefaultPortfolio" is class A, AccountsEditor is class B, and AccountsTableModel is class C. The line given in the second stack trace element is the line in C's constructor which calls Class A's method.
    Debugging, I stop inside C's constructor. Before anything happens, debugger says this$1 is null. Then I step, and it calls super(), and now this$1 is an instance of class B (AccountEditor), but it's own this$1 (which should be an instance of class A) is still null.
    I'm calling C's constructor from within B's constructor (but not A's), not sure if that makes a difference.
    Can anyone explain what's going on here, and (hopefully) how I can work around it?
    Thanks for any help.
    When i debug

    hm, I really don't know what is happening but I want to tell you about something that is not nice in your code and possibly it could cause the error.
    Code behaves somwhat strange when you pass this out of a constructor. You do this implicitly when you create an inner classe which implicitly gets a reference to the outer class. Also just simple method calls can cause such effects.
    This is because the construction process it not finished but methods are already called.
    Even worse: the sub classes constructor possibly did not even start. Special to java is the fact that a method call can lead to an overridden method of a sub class who's constructors has not even passed the super() command.
    My guess now is that you have that some kind of this situation in your code. You create an inner class in a constructor. That inner class calls back a method on the outer class. Now say that the method you are calling is defined in a sub class who's constructor still stucks in super() call. There we are.
    I found a thread in a news group that covers exactly this problem:
    It is therefore a good idea only to call private methods from constructors (that should then also call only private methods). Also if inner classes are created in the constructor then they should not call any non trivial / non private methods of the outer class. Calling overridden methods out of constructors should be avoided strictly!
    Perhaps this has nothing to do with your problem. I cannot tell for sure.
    But this sounds quite interesting.
    Please tell me if my guess was right and if not post simple code the illustrated your problem.
    Here a simple example also throwing NullPointerException:
    class Outer {
      int i = 42;
      abstract class InnerSuper {
        InnerSuper() {
          foo();
        abstract void foo();
      class InnerSub extends InnerSuper {
        void foo() {
          System.out.println(i);
      public void bar() {
        new InnerSub();
      public static void main(String[] args) {
        Outer o = new Outer();
        o.bar();
    } It causes a NullPointerException because the InnerSub constructor did not run. I copied the example from a news group thread i found.
    http://groups.google.de/group/comp.lang.java.programmer/browse_thread/thread/897fba792d689b29/a1ba2ed708636a30?q=inner+class+outer+this+reference+NullPointerException&rnum=4&hl=de#a1ba2ed708636a30
    Here is a even simpler example of strange behavior - even without NullPointerExceptions.
    class A {
         A() {
              System.out.println(getName());
         String getName() {
              return "A";
    class B extends A {
         String NAME = "B";
         String getName() {
              return NAME;
    new B();It will output null instead of B.
    regards
    Sven

  • Binding of super class property

    can we bind super class property, for example:
    class A
    private String message;
    pubic String getMessage()
    return "My Message";
    public void setMessage( String message )
    this.message = message;
    class B extends A
    }now my managed bean returns me a collection of class B objects, and i want to bind in JSF page poperty of its super class like that:
    <h:outputText value="#{b.message}" />
    It gives me a error "PropertyNotFoundException: b.message.
    Is it possible in JSF ??
    regards,
    Y_NOT_

    I threw a quick test up on my JSF app and it works fine for me. It is not because of polymorphism. It must be in the way you are accessing the method. A typo or something small. Or perhaps it's because you are using a collection (and not accessing the Collection properly)?
    CowKing

  • 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

  • Error while calling a super class public method in the subclass constructor

    Hi ,
    I have code like this:
    CLASS gacl_applog DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS:
                create_new_a
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXPORTING  pfx_log_hndl TYPE balloghndl
                   EXCEPTIONS error
    ENDCLASS.
    CLASS gacl_applog IMPLEMENTATION.
      METHOD create_new_a.
        DATA: ls_log TYPE bal_s_log.
      Header aufsetzen
        MOVE pf_extnumber TO ls_log-extnumber.
        ls_log-object     = pf_obj.
        ls_log-subobject  = pf_subobj.
        ls_log-aluser     = sy-uname.
        ls_log-alprog     = sy-repid.
        ls_log-aldate     = sy-datum.
        ls_log-altime     = sy-uzeit.
        ls_log-aldate_del = ls_log-aldate + 1.
        CALL FUNCTION 'BAL_LOG_CREATE'
             EXPORTING
                  i_s_log      = ls_log
             IMPORTING
                  e_log_handle = pfx_log_hndl
             EXCEPTIONS
                  OTHERS       = 1.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID      sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    CLASS gcl_applog_temp DEFINITION INHERITING FROM gacl_applog.
      PUBLIC SECTION.
        DATA: log_hndl   TYPE balloghndl READ-ONLY
            , t_log_hndl TYPE bal_t_logh READ-ONLY
        METHODS: constructor
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXCEPTIONS error
               , msg_add      REDEFINITION
               , display      REDEFINITION
    ENDCLASS.
    CLASS gcl_applog_temp IMPLEMENTATION.
      METHOD constructor.
        CALL METHOD create_new_a
               EXPORTING  pf_obj       = pf_obj
                          pf_subobj    = pf_subobj
                          pf_extnumber = pf_extnumber
               IMPORTING  pfx_log_hndl = log_hndl.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    A public method of Super class has been called from the constructor of the sub class. we are getting the syntax error :
    ' In the constructor method, you can only access instance attributes, instance methods, or "ME" after calling the constructor of the superclass…'
    Can you please suggest how to change the code with out affecting the functioanlity.
    Thank you ,
    Lakshmi.

    Hi,
    Call that method by instance of Subclass.   OR
    SUPER-->method.
    Read very useful document
    Constructors
    Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. There are two types of constructors - instance constructors and static constructors. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class.
    The instance constructor of a class is the predefined instance method CONSTRUCTOR. You declare it in the public section as follows:
    METHODS CONSTRUCTOR
            IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL]..
            EXCEPTIONS.. <ei>.
    and implement it in the implementation section like any other method. The system calls the instance constructor once for each instance of the class, directly after the object has been created in the CREATE OBJECT statement. You can pass the input parameters of the instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS additions in the CREATE OBJECT statement.
    The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. You declare it in the public section as follows:
    CLASS-METHODS CLASS_CONSTRUCTOR.
    and implement it in the implementation section like any other method. The static constructor has no parameters. The system calls the static constructor once for each class, before the class is accessed for the first time. The static constructor cannot therefore access the components of its own class.
    Pls. reward if useful....

  • Can't get my class's getter method to work properly.

    Hello, I am new to Java programming, although I come from C and C++. This is my first post. I am working on a basic Library application that can Checkout and Return books. Eventually I would like to add the ability to read from and write to an XML file containing data for every book.
    My problem right now is that I cannot get my getter method within my Book class to work properly. When I call getData() from within main, and pass the appropriate arguments, instead of filling the variables with that object's data, it leaves them blank! Please help me.
    Here is my method within the Book class, the person and id_num are private.
    /* Gets general Book Instance Data and fills parameters with it */
         public void getData(String n, int num, String c, String d)
              n = this.person;
              num = this.id_num;
              c = this.checkout_date_string;
              d = this.due_date_string;
         }Here is how I am attempting to use it in main:
    String name = "";
    int number = 0;
    String checkout = "";
    String due = "";
    Book book1;
    /*Sets person = John Smith and id_num = 10763*/
    book1 = new Book("John Smith", 10763);
    /*Gets Checkout (todays) date and sets a due date in 2 weeks*/
    book1.Checkout();
    book1.getData(name, number, checkout, due);
    System.out.println("Book1:\n Checkout Date: " + checkout +
                             "\n Due Date: " + due + "\n Is it late: " + book1.isLate() +
                             "\n Person who checked it out: " + name + "\n ID number: " + number +
                             "\n ");Then, Here is the Output:
    Book1:
    Checkout Date:
    Due Date:
    Is it late: false
    Person who checked it out:
    ID number: 0
    Edited by: 987158 on Feb 9, 2013 11:52 AM

    >
    Well I went ahead and made separate methods to return each value. I suppose that will work just as well, especially since now I don't have to declare a bunch of strings and int's to hold the data and pass to the method.
    >
    Well this would never work anyway
    public void getData(String n, int num, String c, String d)None of those can be changed within the method. Strings are immutable and 'int' is passed by value. Each of those parameters will have the same value after the method exits as they did before it was called.
    Your book class should be using 'setters' to set the value of its instance variables.

  • Calling a method from a super class

    Hello, I'm trying to write a program that will call a method from a super class. This program is the test program, so should i include extends in the class declaration? Also, what code is needed for the call? Just to make things clear the program includes three different types of object classes and one abstract superclass and the test program which is what im having problems with. I try to use the test program to calculate somthing for each of them using the abstract method in the superclass, but its overridden for each of the three object classes. Now to call this function what syntax should I include? the function returns a double. Thanks.

    Well, this sort of depends on how the methods are overridden.
    public class SuperFoo {
      public void foo() {
         //do something;
      public void bar(){
         //do something
    public class SubFoo extends SuperFoo {
       public void foo() {
          //do something different that overrides foo()
       public void baz() {
          bar(); //calls superclass method
          foo(); //calls method in this (sub) class
          super.foo(); //calls method in superclass
    }However, if you have a superclass with an abstract method, then all the subclasses implement that same method with a relevant implementation. Since the parent method is abstract, you can't make a call to it (it contains no implementation, right?).

  • Overwriting a method of a super class in the subclass ???

    Hi,
    can somebody tell me whether it's possible to add a new implementation of a method in the sub class which is inherited from a super class?
    I want to model my program in that way:
    1. I define a super class with some implemented methods.
    2. This class should be inherited in a sub class. One method should be used as it was implemented in the super class but another method should be overwritten in the subclass.
    I know this concept from Java but I couldn't find a way how to do it in ABAP
    Many thanks for any help!
    Best regards,
    Birgit

    hi,
    yeas you can do it,
    Subclass can re-implement  the inherited public and protected methods from superclass.Class C1 contains method METH1(public) and METH2(protected), both of which are modified and re-implemented in  its subclass C2.also you can have ur own methods in subclass.Objects are created out of both classes and the method METH1 for both objects are called.
    Output of the program demonstrates different behaviour for method METH1 of class C1 and C2.
    This demonstrates the theme.
    REPORT YSUBDEL.
    CLASS C1 DEFINITION.
      PUBLIC SECTION.
       METHODS : METH1.
      PROTECTED SECTION.
       METHODS METH2.
      ENDCLASS.
    CLASS C1 IMPLEMENTATION .
      METHOD : METH1.
       WRITE:/5 'I am meth1 in class C1'.
       CALL METHOD METH2.
      ENDMETHOD.
      METHOD : METH2.
       WRITE:/5 ' I am meth2 in class C1 '.
      ENDMETHOD.
    ENDCLASS.
    CLASS C2 DEFINITION INHERITING FROM C1.
    PUBLIC SECTION.
      METHODS : METH1 redefinition,
      meth3.
    PROTECTED SECTION.
      METHODS : METH2 redefinition.
    ENDCLASS.
    CLASS C2 IMPLEMENTATION.
    METHOD METH1.
       WRITE:/5 'I am meth1 in class C2'.
       call method meth2.
    endmethod.
      METHOD : METH2.
      WRITE:/5 ' I am meth2 in class C2 '.
    ENDMETHOD.
    METHOD : METH3.
      WRITE:/5 ' I am own method of class C2'.
    ENDMETHOD.
    endclass.
    START-OF-SELECTION.
      DATA : OREF1 TYPE REF TO C1 ,
             OREF2 TYPE REF TO C2.
      CREATE OBJECT :  OREF1 , OREF2.
      CALL METHOD : OREF1->METH1 ,
                    OREF2->METH1.
    hope it helps,
    regards

  • Calling a particular Method of all subclass from a super class

    hi
    I have a class 'A' which is a super class for 'B' ,'C' , 'D'
    my main method is in the class Main and while on the run i am calling methods of B,C,D form this main class.
    but as the first step of execution i need to call a init method which has been defined in all the sub-classes. and there can be any no of sub-classes and all will have the init method and i have to call the init method for all classes. is this possible to do that in runtime. ie i wil not be knowing the names of sub-classes.
    thanks
    zeta

    Sorry if i had mislead you all.
    I am not instantiating from my super class.
    as mjparme i wanted one controller class to do the
    init method calls
    so i got it working from the link you gave.
    URL url = Launcher.class.getResource(name);
    File directory = new File(url.getFile());
    This way i can get all the classes in that
    in that package
    and from reflection i can get whether it is
    her it is a sub class of the particular super class
    and i can call the init methods by making the init
    methods static
    thanks for the help
    zetaThis is a rather fragile solution.
    If the problem is one of knowing which subclasses exist, I would suggest specifying them explicitly via configuration (system property or properties file or whatever).
    One thing that's not entirely clear to me: Is the init going to be called once for each subclass, or once for each instance of each subclass? It sounds to me like it's once per class, but I want to make sure.

  • Calling the super class method from the subclass

    Hi all,
    I have a question about inheritence and redefinition of methods. Is it possible to call the superclass implementation of a method which is redefined in the subclass in another method of the subclass?There are possbilities like creation of an explicit super class instance or delegating the super class method implementation to another method which is also protected etc. What i mean is, is there a direct way of calling it?We have ,me,   as the reference for the instance we have(which is the subclass instance in this case), is there also a way of pointing the superclass implementation(with super we can reference in the subclass redefinition, my question is if we have such a parameter in other methods of the subclass too)
    Thanks in advance
    Sukru

    Hi,
    The super reference can only be used in redefined methods to call superclass implementation . So probably what you can do is use upcasting and access the required superclass implementation. I can think of only this way...;-)
    Ex data lr_super type ref to cl_superclass
    lr_super = lr_subclass.
    lr_super->method().
    ~Piyush Patil

  • Trying to use super class's methods from an anonymous inner class

    Hi all,
    I have one class with some methods, and a second class which inherits from the first. The second class contains a method which starts up a thread, which is an anonymous inner class. Inside this inner class, I want to call a method from my first class. How can I do this?
    If I just call the method, it will use the second class's version of the method. However, if I use "super," it will try to find that method in the Thread class (it's own super class) and complain.
    Any suggestions?
    Code:
    public class TopClass
         public void doSomething(){
              // do something
    =============================
    public class LowerClass extends TopClass
         // overrides TopClass's doSomething.
         public void doSomething(){
              // do something
         public void testThread(){
              Thread t = new Thread(){
                   public void run(){
                        doSomething();               //fine
                        super.doSomething();          //WRONG: searches class Thread for doSomething...
              t.start();
    }

    Classes frequently call the un-overridden versions of methods from their superclasses. That's that the super keyword is for, if I'm not mistaken.You're not mistaken about the keyword, but you're not calling the superclass method from a subclass. Your anonymous inner class is not a subtype of TopLevel. It's a subtype of Thread.
    Here it is no different, except that I happen to be in a thread at the time.It's vastly different, since you're attempting to call the method from an unrelated class; i.e., Thread.
    I could also be in a button's action listener, for example. It seems natural to me that if I can do it in a method, I should be able to do it within an anonymous inner class which is inside a method.If you were in an button's action listener and needed to call a superclass' implementation of a method overridden in the button, I'd have the same questions about your design. It seems smelly to me.
    ~

  • Weird one..  i can't return a variable from the extended to the super class

    Hey everyone, i hope i'm not annoying you guys :)
    So today's problem is to return a variable (int) from a method of the extended class and print it ont the super class.
    I'm just testing the super class , if it works fine.
    So the extended class ( FileIO) just read the file txt and return the integer or string ( from the txt file)
    I already did a main method to that class and tested it, it works fine.
    So now the problem is to print the integer ( that the extended class gets from the txt. ) inside the Super class. I mean , is the same thing but now im testing the Super class , just have to do the same thing, a super class method calls the extended class method and receive the integer from the txt file.
    i think the problem is when i create the instance of the FileIO object , maybe its constructor ...i don't know.
    The name of the txt file is passed from the super class to the extended class, but i think the error is not from there.
    this.aero_le = new BufferedReader(new FileReader(super.ficheiroleitura_aero()));  //  super calls ficheiroleitura_aero()  and receive the name of the txt file ( e.g "temp.txt")  so i think that is correct.
    here's the code of the Super class public class Aeroporto {
         private String filereader_voo = "temporary.txt";
         private String filereader_aero = "temp.txt";
         private String siglaAero = "";
         public FileIO file;
         public Aeroporto(){};
         public Aeroporto(String filereader_voo, String filereader_aero) throws IOException{
              this.filereader_voo = filereader_voo;
              this.filereader_aero =filereader_aero;     
              file = new FileIO();
         public String siglaAero() {
              return siglaAero; }
         public String filereader_aero(){
              return filereader_aero;
    public int nrLines() throws IOException{   // it was supose to retunr the number of lines ( integer) from the txt file .
              return Integer.parseInt(file.lerLinhaN(1,1));
    // main() {
    Aeroporto a = new Aeroporto();
              int v = a.nrLines();
              System.out.print(v);
    // ***********************************************************+
    // Extended Class
    public class FileIO extends Aeroporto{
         private String ficheiroescrita;
         private PrintWriter vooescreve, aeroescreve ;
         private BufferedReader voo_le, aero_read;
         public FileIO(){}
         public FileIO(String filereader_voo, String filereader_aero, String ficheiroescrita) throws IOException {
              super(filereader_voo, filereader_aero);
              this.ficheiroescrita = ficheiroescrita;
              //If file does not exists , create one.
              try{
                   this.aero_read = new BufferedReader(new FileReader(super.filereader_aero()));
                   aero_read.close();
              catch(IOException ex){
                   this.aeroescreve = new PrintWriter(new FileWriter(ficheiroescrita));
                   aeroescreve.close();
    public String lerLinhaN(int line, int column) throws IOException{  // this method works fine , i already tested this class.
              this.aero_read = new BufferedReader(new FileReader(super.filereader_aero()));
              for(int i = 0; i != line-1; ++i) aero_read.readLine();
              String linha = aero_read.readLine();
              String [] words = linha.split(" ");
              return words[column-1];
    Maybe the error is that i use to test the Super class a default contructor on both classes... i don't know where the error is, i also did two small classes ( super and another that extends ) and get the string "Hello" from the super and print it inside the extended..and it works, that's why i think the error is when i call the extended class .. need help.
    thanks.

    Ok,
    This one might actually work... atleast it compiles.import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.File;
    import java.io.PrintWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    public abstract class FileIO {
         public static boolean CreateOutputFileIfNotExists(
              String outputFilename //the name of the file to ensure exists.
         ) throws IOException
              final String functionName = "FileIO.CreateOutputFileIfNotExists";
              boolean retVal = false;
              //If the output file does does not exist then create it.
              //post condition: output file exists or an IOException has been thrown.
              BufferedReader infile = null;
              try{
                   infile = new BufferedReader(new FileReader(outputFilename));
                   retVal = true;
              } catch(IOException ex) {
                   PrintWriter outfile = null;
                   try {
                        outfile = new PrintWriter(new FileWriter(outputFilename));
                        retVal = true;
                   } catch(IOException ex2){
                        throw new IOException(functionName + ": cannot create output file " + outputFilename, ex2);
                   } finally {
                        outfile.close();
                        if (outfile.checkError()) {
                             throw new IOException(functionName + ": error on output stream " + outputFilename);
              } finally {
                   try {
                        infile.close();
                   } catch(IOException ex){
                        throw new IOException(functionName + ": cannot close output file " + outputFilename, ex);
              return(retVal);
         public static String readLine(
                   String  inputFilename //the name of the file to read.
              , int     lineNumber    //1 based number of the line to read from.
         ) throws IOException
              final String functionName = "FileIO.readLine";
              String outputLine = null;
              // reads the numbered "lineNumber" from "inputFilename".
              BufferedReader infile = null;
              try {
                   infile = new BufferedReader(new FileReader(new File(inputFilename)));
                   for(int i=1; i<lineNumber; ++i) infile.readLine();
                   outputLine = infile.readLine();
              } catch(IOException ex){
                   throw new IOException(functionName + ": cannot read input file " + inputFilename, ex);
              } finally {
                   try {
                        infile.close();
                   } catch(IOException ex){
                        throw new IOException(functionName + ": cannot close input file " + inputFilename, ex);
              return(outputLine);
         public static String readWord(
                   String inputFilename  //the name of the file to read.
              , int lineNumber        //1 based number of the line to read from.
              , int wordNumber        //0 based number of the word to read.
         ) throws IOException
              final String functionName = "FileIO.readWord";
              String outputWord = null;
              // reads the numbered space-seperated "wordNumber" from the numbered "lineNumber" of "inputFilename"
              try {
                   String[] words = FileIO.readLine(inputFilename, lineNumber).split(" ");
                   if (wordNumber>0 && wordNumber<words.length) outputWord = words[wordNumber-1];
              } catch(IOException ex){
                   throw new IOException(functionName + ": cannot read input file " + inputFilename, ex);
              return(outputWord);
    }Design notes... FileIO is a generic helper class... there is nothing specific to Airports, flights, or any other "domain" specific stuff in it... so it's re-usable... you can keep it and reuse it on other projects, or even share it with your friends.
    So... The airport class will just call the static methods on FileIO like this    ....
        int lineNumber=1;
        int wordNumber=1;
        String airportCode = FileIO.readWord(airportsFilename, lineNumber, wordNumber);
        ....How's that?
    corlettk: my now mandatory edit.

  • 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.

Maybe you are looking for

  • Error while loading data to Infocube using DTP.

    Dear All I am facing problem while uploading data in Zinfocube. Up to PSA the data is loaded and not showing any error but when we try to upload the data from PSA to INFOCUBE through a DTP, It ens up showing error message (Error while updating to tar

  • User Exit for Aleaud Idoc

    Hi everybody!!! Does anybody knows if exist any user-exit or badi for aleaud idoc??? We receive an Idoc from PI and we sent an Aleaud Idoc to Pi as Ack and we need populatel some fields. Thanks a lot

  • Rolling years dynamically updated from a business rule

    Hi All, Can anyone advise on how they have solved the problem of rolling opening balances from one year to another in essbase\planning. Our users could potentially want to forecast out x number of years and we don't want to necessarily hardcode out t

  • Linking Advance (Deposit/Commitment ) to an Order

    When a Deposit Invoice is created in AR for each Item Line & linked to an Order in OE, Auto Invoice gives an error. Are there any particular seups required for this purpose ? How to link more tahn one advance to a single Order ?

  • FRM-41213 running a report.

    When I restart OC4J and then I try to run a report a I get the error FRM-41213. I need to start manually the report engine, using something like /rwservler/showjobs before I can run the report. I read the metalink note 218835.1 and it seems I runned