Hi Everyone,

Thanks for viewing this thread.

How do I do the code similar in Java? The syntax for the code below is C#.

    public class Child : Parent
    {
        public Child(String a, String b) : base(c)
        {

        }
    }

I would like to seek for your help on Java. I have found the similar way to add ": base(c)" behind the child overloaded constructor but it didn't work. Is there any thing I have to do for Java?

Thanks for the time.

Is this what you mean?

class A {
  public A(int i) { ... // constructor
  ...
}

class B extends A {
  public B(int i) {
     super(i);  // calls superclass's constructor
  }
  ...
}

I guess line 7 chould be public B(int i, String a, String b) { so that it would imitate line 3 in the OP post?

commented: Yeah man! you are right as well! thanks for the contribution!! +3

Well yes, I guess the exact equivalent would just be

 public class Child extends Parent   {
      public Child(String a, String b) {
          super(c);
      }
}
commented: Yes; exactly. +6
commented: thank you!! +3

Thank you for all the contribution. I finally figured out with all your input. =)

public class Child extends Parent   {
      public Child(String a, String b, String c) {
          super(c);
      }
}

It is similar to JamesCherrill post but just to add String c in the child overloaded constructor so that the system can capture the value to the base contructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.