• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

flow fo code -------

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read Qustion
public class Star {
Star() {
System.out.println("Star");
}
Star(String s1) {
super();
System.out.println(s1 + " is a Star");
}
Star(String s2, String s3) {
this("Mercury");
System.out.println( s2 + " and " + s3 + " are also Stars");
}
public static void main(String [] args) {
Sun sun = new Sun();
Sun sun1 = new Sun("Venus");
Sun sun2 = new Sun("Mars", "Earth");
}
}
class Sun extends Star {
public Sun() {
System.out.println("Star Wars1");
}
public Sun(String v1) {
super(v1, "Saturn");
System.out.println("Star Wars2");
}
public Sun(String v2, String v3) {
if ( v2.substring(0, v2.length()).length() > v3.length())
System.out.println("Mission to Mars");
else
System.out.println("Earth");
}
}

answer are
Star
Star Wars1
Mercury is a Star
Venus and Saturn are also Stars
Star Wars2
Star ///////////// Problem.with this star..
Earth
My Qustion is ???
When u call Overloaded consutructor with two parameter HOW ..
Second Star will be printed....

Thnx
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi deepak,
its really simple.whenever a class extends another class then we should call super(with any no. of arguments) as the first statement of sub-class constructor .if we dont specify it then automatically the default constructor of the super-class is called.
so here this////star is for that reason.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deepak
Please read the JavaRanch Name Policy and re-register using a name that complies with the rules.
Thanks for you cooperation.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
A teeny tiny vulgar attempt to get you to buy our stuff
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic