Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (3.5k points)

How do I call a constructor from another (within the same class not from a subclass)? And what’s the best way to do it?

1 Answer

0 votes
by (46k points)

The best way to do this is to use “this” which is an explicit constructor invocation. Here's the syntax:

public class Foo


   private int z;

   public Foo()




   public Foo(int z)


       this.z = z;



Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories