-3

I have object like:

import java.math.BigDecimal;
public class Obj {
    BigDecimal Sal;
    int EMPID;

    public Obj(BigDecimal Sal, int EMPID) {
        this.Sal= Sal;
        this.EMPID= EMPID;
    }
}

Now I wanna create Instance of Obj with constructor call.

Obj a = new Obj(45,34); // getting error here

Tried this also: Obj a = new Obj( (BigDecimal) 45,34);

Error:

Obj (java.math.BigDecimal, int) in Obj cannot be applied to (int, int)

 

LoganPaul
  • 59
  • 11
  • 6
    `45` is not a `BigDecimal`. Use either `new Obj(BigDecimal.valueOf(45), 34)`, `new Obj(new BigDecimal("45"), 34)` or `new Obj(new BigDecimal(45), 34)` – ernest_k Mar 17 '19 at 11:02
  • 2
    As an aside, even though EMPID is in uppercase in the real world, let Java code conventions win in Java: use `empId` or `empid`. – Ole V.V. Mar 17 '19 at 11:07

1 Answers1

3

BigDecimal is a class and you need to create an instance of it. Do: Obj a = new Obj(new BigDecimal(45), 34)

5ar
  • 2,069
  • 10
  • 27
  • `BigDecimal` is not a *Object* but a **class**. – Vishwa Ratna Mar 18 '19 at 05:18
  • 1
    I was aiming at what data type it is, i.e. objects vs primitives. Of course the name itself is a class and an instance of that class is an object, I thought that that was obvious. However I understand the need to be precise so that someone else might not get confused by the nomenclature. – 5ar Mar 18 '19 at 11:53