Results 1 to 6 of 6
Thread: super
- 01-22-2009, 07:37 PM #1
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;
}
}
- 01-22-2009, 07:38 PM #2
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();
}
}
- 01-22-2009, 09:39 PM #3
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:
-
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.
- 01-23-2009, 02:01 AM #5
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)
- 01-23-2009, 03:07 PM #6
Similar Threads
-
this() vs super()
By Hevonen in forum New To JavaReplies: 9Last Post: 12-04-2008, 01:43 PM -
Inheritance and (super)
By pheonix in forum New To JavaReplies: 12Last Post: 10-20-2008, 03:00 PM -
Super CSV 1.20
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11-27-2007, 08:22 PM -
Super CSV 1.15
By JavaBean in forum Java SoftwareReplies: 0Last Post: 10-16-2007, 06:37 PM -
Use super. or this.
By Marcus in forum New To JavaReplies: 1Last Post: 07-05-2007, 06:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks