[Solved] I am getting null as an output in Java [closed]


Reading your code was very hard. A method and a variable with the same name is bound to cause confusion. Anyway: You are never assigning any value to the field v2, so it is always printed as null — the default value that fields have when created.

It maybe a copy-paste error where you forgot to change v1 to v2 after pasting. You can best tell yourself.

Next time please see if you can do a Minimal, Complete, and Verifiable example. I bet you will find the error before getting your question ready for posting. 🙂

1

solved I am getting null as an output in Java [closed]