Question: I tried like this. The file name of `ClassA` is instanceAndClassMethods

```
class ClassA

    def initialize #constructor 
        puts "This is my constructor" 
    end

    def initialize(a,b)
        c=a-b
        puts c
    end
end

```

From other class I called above class as both are in same folder like:

`require './instanceAndClassMethods' #filename` should not contain spaces

`obj = ClassA.new #constructor` are automatically called when object is created

```
obj=ClassA.new(33,33)

```

When I run from command prompt, I'm getting:

```
Traceback (most recent call last):
        2: from callMeth.rb:4:in `<main>'
        1: from callMeth.rb:4:in `new'
C:/Users/vkuma102/Desktop/Ruby Learning/instanceAndClassMethods.rb:7:in `initial
ize': wrong number of arguments (given 0, expected 2) (ArgumentError)

```

If this is the case then it is difficult right whereas we can call both normal constructor and constructor with parameters in Java

Answer: 
No, Ruby does not have method overloading. Unlike e.g. Java or Crystal, you only get one method of the same name per class. Your second `def` is overwriting the first. It's like writing `foo = 7; foo = 19` - the value `7` is not accessible any more from `foo`.

If you want to distinguish different argument lists, you need to do it yourself. Fortunately, unlike Java, Ruby has optional parameters (i.e. parameters with default values):

```
class ClassA
  def initialize(a=nil, b=nil)
    if a && b
      c = a - b
      puts c
    else
      puts "This is my constructor" 
    end
  end
end

```
In addition to the *overloading* solution, which Amadan suggested, you can also provide factory methods to complement your constructor, for example:

```
class Foo

  def initialize(_a = nil, _b = nil, _c = _nil)
    @a, @b, @c = _a, _b, _c
  end

  # factories
  def self.make_fancy_foo(x,y,z)
    new(bar(x),y+1,baz(z-y))
  end
  def self.make_special_foo(x)
    new(x,x,x)
  end

end

```

This is how you can use them:

```
foo1 = Foo.new
foo2 = Foo.new(88)
foo3 = Foo.new(3,6,9)
foo4 = Foo.make_fancy_foo(7,-1,5)
foo5 = Foo.make_special_foo(6)

```