# My doubt is in line 4 how can a TaxCalculator class be declared as field calculator

**URL:** <https://forum.codewithmosh.com/t/my-doubt-is-in-line-4-how-can-a-taxcalculator-class-be-declared-as-field-calculator/8448>\
**Category:** Java\
**Created:** [November 11, 2021, 8:22am UTC](https://forum.codewithmosh.com/t/my-doubt-is-in-line-4-how-can-a-taxcalculator-class-be-declared-as-field-calculator/8448 "2021-11-11T08:22:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![karthikreddy](https://avatars.discourse-cdn.com/v4/letter/k/a183cd/32.png) [@karthikreddy](https://forum.codewithmosh.com/u/karthikreddy)\
**Post date:** [November 11, 2021, 8:22am UTC](https://forum.codewithmosh.com/t/my-doubt-is-in-line-4-how-can-a-taxcalculator-class-be-declared-as-field-calculator/8448/1 "2021-11-11T08:22:44Z")

</div>

![Screenshot 2021-11-11 at 1.47.57 PM](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/f/fd42230f30110721239a0398ac61241146a5dbfc.jpeg)

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://forum.codewithmosh.com/u/Paul)\
**Post date:** [November 11, 2021, 6:00pm UTC](https://forum.codewithmosh.com/t/my-doubt-is-in-line-4-how-can-a-taxcalculator-class-be-declared-as-field-calculator/8448/2 "2021-11-11T18:00:27Z")

</div>

So, every variable (or field) must have a certain type. it could be `int`, `String` or whatever and you declare it as follows;

```auto

String myString;
int number;

```

In the same way `calculator` is declared as a variable of type `TaxCalculator` and you declare it as

`TaxCalculator calculator;`

---

<div class="post-metadata">

**Author:** ![karthikreddy](https://avatars.discourse-cdn.com/v4/letter/k/a183cd/32.png) [@karthikreddy](https://forum.codewithmosh.com/u/karthikreddy)\
**Post date:** [November 11, 2021, 11:34pm UTC](https://forum.codewithmosh.com/t/my-doubt-is-in-line-4-how-can-a-taxcalculator-class-be-declared-as-field-calculator/8448/3 "2021-11-11T23:34:12Z")

</div>

Thanks Paul but if we declare datatype as a String we can only give " sentences" for int only numbers. what we can only declare as TaxCalculator

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://forum.codewithmosh.com/u/Paul)\
**Post date:** [November 12, 2021, 4:50am UTC](https://forum.codewithmosh.com/t/my-doubt-is-in-line-4-how-can-a-taxcalculator-class-be-declared-as-field-calculator/8448/4 "2021-11-12T04:50:16Z")

</div>

You can do all the things with calculator that the `TaxCalculator` class allows you to do. So if it has eg a `calculateTax` method you can call it using `calculator.calculateTax()`.
