locked
local variable not called RRS feed

  • Question

  • I keep getting a error that The value of the local variable x is not used

    with this code:

    package app;
    public class Constructors {
      public Constructors(int value){
        System.out.println(value);
      }
        public static void main(String[] args) {
          //create instances here
          Constructors x = new Constructors(5839);
        }
      }

    Friday, April 17, 2020 5:36 AM

All replies

  • You are not using the variable "x"  somewhere. You can delete the left hand side of the assignment.

    Note: Constructors are not for user interaction, their main job is initializing the object.


    www.cihanyakar.com

    Friday, April 17, 2020 6:42 AM
  • Hi Kahasim,

    Sorry for delay in reply.

    According to your description, your code works with java. And this questions is more about java syntax problem, maybe you can refer this similar issue here: https://stackoverflow.com/a/36728987/11557747 

    Besides, we also recommend you can redirect to stackoverflow with java tag, then related community members will provide dedicated support for you.

    Thank you for understanding.

    Best Regards,

    Dylan 



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, April 20, 2020 5:14 AM