Results 1 to 6 of 6

Thread: super

  1. #1
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default super

    Hello to everybody. I want to parse some variables from the superclass to subclass i ve tried to use supper in the following example but it doesn t work. Anyone can help

    This is the superclass:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package ofthalmiatreio;

    /**
    *
    * @author kris
    */
    public class Asthenhs {

    private String epwnymo;
    private String onoma;
    private int tilefwno;
    private String asForeas;

    Asthenhs(Asthenhs ob){

    epwnymo=ob.epwnymo;
    onoma=ob.epwnymo;
    tilefwno=ob.tilefwno;
    asForeas=ob.asForeas;
    }

    public Asthenhs(){

    }
    public Asthenhs(String ep, String onom, int til, String as){

    this.epwnymo=ep;
    this.onoma=onom;
    this.tilefwno=til;
    this.asForeas=as;
    }
    public void setEpwnymo(String ep){

    this.epwnymo=ep;
    }
    public String getEpwnymo(){

    return epwnymo;
    }
    public void setOnoma(String onom){

    this.onoma=onom;
    }
    public String getOnoma(){

    return onoma;
    }
    public void setTilefwno(int til){

    this.tilefwno=til;
    }
    public int getTilefwno(){

    return tilefwno;
    }
    public void setasForeas(String as){

    this.asForeas=as;
    }
    public String getasForeas (){

    return asForeas;
    }

    }

  2. #2
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    And this is the code with subclass:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package ofthalmiatreio;
    import java.util.*;
    import java.text.*;

    /**
    *
    * @author kris
    */
    public class istorikoAsthenous extends Asthenhs {

    private String astheneies;
    private String sintages;

    private int day;
    private int month;
    private int year;

    DateFormat customFormat =
    new SimpleDateFormat("dd MMM yyyy");
    DateFormat mediumFormat =
    DateFormat.getDateInstance(DateFormat.MEDIUM);

    istorikoAsthenous(istorikoAsthenous ob){

    super(ob);
    astheneies=ob.astheneies;
    sintages=ob.sintages;
    day=ob.day;
    month=ob.month;
    year=ob.year;
    }
    public istorikoAsthenous(){

    astheneies="NULL";
    sintages="NULL";
    day=0;
    month=0;
    year=0;
    }

    public istorikoAsthenous(String astheneies, int day, int month, int year, String sintages, String epwnymo){

    this.astheneies=astheneies;
    this.day=day;
    this.month=month;
    this.year=year;
    this.sintages=sintages;

    super(epwnymo);
    }
    public void setAstheneies(String asth){

    astheneies=asth;
    }
    public String getAsteneies(){

    return astheneies;
    }
    public void setDay(int day){

    day=Calendar.DATE;
    this.day=day;
    }
    public int getDay(){

    return day;
    }
    public void setMonth(int month){

    month=Calendar.MONTH;
    this.month=month;
    }
    public int getMonth(){

    return month;
    }
    public void setYear(int year){

    year=Calendar.YEAR;
    this.year=year;
    }
    public int getYear(){

    return year;
    }
    public void setSintages(String sint){

    sintages=sint;
    }
    public String getSintages(){

    return sintages;
    }

    public void showIstoriko(){

    System.out.println("H pathisi tou asthenous einai:"+astheneies);
    System.out.println("H imerominia eksetasis einai:"+ day +"/"+ month+"/"+year);
    System.out.println("I sintagi tou giatrou:"+sintages);
    }
    public static void main(String [] args){

    istorikoAsthenous a= new istorikoAsthenous();
    a.setAstheneies("mywpia");
    a.setDay(3);
    a.setMonth(11);
    a.setYear(2009);
    a.setSintages("gyalia");
    a.showIstoriko();
    }

    }

  3. #3
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    the compiler said "call to super must be first statement in constructor" when i try to parse the variables of superclass in the constructor of subclass.:rolleyes:

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    So do that. Make the super(...) the first call in the subclass's constructor when you need to make an explicit call to the super's constructor.

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    what fubarable said. and if you want to call super last, you'll need to use: super.istorikoAsthenous(); or something like that...
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  6. #6
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

Similar Threads

  1. this() vs super()
    By Hevonen in forum New To Java
    Replies: 9
    Last Post: 12-04-2008, 02:43 PM
  2. Inheritance and (super)
    By pheonix in forum New To Java
    Replies: 12
    Last Post: 10-20-2008, 04:00 PM
  3. Super CSV 1.20
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-27-2007, 09:22 PM
  4. Super CSV 1.15
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-16-2007, 07:37 PM
  5. Use super. or this.
    By Marcus in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 07:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •