Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get method returns null in java

I’m so new to Java and I cant find what im doing wrong.
I got a error once that said GetAd() isnt undefined for the type Test, but it is public, i dont understand.

here is the codecode:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are not updating the instance variable ad in your SetAd() method and hence when you call GetAd() it returns the default null value.

Replace name = ad; in your SetAd() method to ad = name;; In other words, do not update the local variable of the method but rather update the instance variable.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading