Συντονιστής: konnn
Star_Light έγραψε:Owing to constructor chaining , when object of child class DemoChild is created , constructor Demo() of the parent class is invoked first and later constructor DemoChild() of the child is created.
public class examples
{
int value1 ;
int value2 ;
examples()
{
value1 = 1;
value2 = 2;
System.out.println("Inside 1st Parent Constructor");
}
examples( int a )
{
value1 = a;
System.out.println("Inside 2nd Parent Constructor");
}
public void display()
{
System.out.println("Value1 === "+value1);
System.out.println("Value2 === "+value2);
}
public static void main(String args[]){
DemoChild d1 = new DemoChild();
d1.display();
}
}
class DemoChild extends examples {
int value3;
int value4;
DemoChild()
{
super(5);
value3 = 3;
value4 = 4;
System.out.println("Inside the Constructor of Child");
}
@Override
public void display()
{
System.out.println("Value1 === "+value1);
System.out.println("Value2 === "+value2);
System.out.println("Value1 === "+value3);
System.out.println("Value2 === "+value4);
}
}
class examples{
int value1;
int value2;
examples(){
value1 = 1;
value2 = 2;
System.out.println("Inside 1st Parent Constructor");
}
Star_Light έγραψε:δεν εκτελειται καθολου αν δεν κανω λαθος? για αυτο η value2 ειναι χωρις τιμη και συνεπως παιρνει 0?
Star_Light έγραψε:δωστε ενα διαγραμμα ροης
Star_Light έγραψε:Δεν ειναι μονο overloading αυτο ειναι και πολυμορφισμός!!!
giannosfor έγραψε:
Τι διάγραμμα ροής θέλεις ?
giannosfor έγραψε:
Για να σε δω,που είναι ο πολυμορφισμός ? Γατάκι
public class examples2
{
int x;
int y;
String name;
String surname;
examples2(int x , int y)
{
this.x=x;
this.y=y;
}
examples2(String name , String surname)
{
this.name=name;
this.surname=surname;
}
public static void main(String args[])
{
examples2 number = new examples2(2,4);
examples2 name = new examples2("Giwrgos","Nikou");
System.out.println(number.y);
System.out.println(number.x);
System.out.println(name.name);
System.out.println(name.surname);
}
}
Star_Light έγραψε:Δεν ειναι μονο overloading αυτο ειναι και πολυμορφισμός!!!
Star_Light έγραψε:Ρε συ η υπερφορτωση που λες.... δεν ειναι ο πολυμορφισμος αλλα με δευτερη ονομασια? ετσι το πηρε καπου χθες το ματι μου!!!!!
Ναι αλλά τι είναι πολυμορφισμός δεν ξέρεις.Star_Light έγραψε:H υπερφόρτωση ειναι ένας τύπος πολυμορφισμού. Δεν το ανέφερα τυχαία