Results 1 to 3 of 3
  1. #1
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Rep Power

    Default Anyone can tell me this??

    How can I modify or update only one member of an object?i.e, if I want to change only roll number of a student in a student class then how can I do this??

    anyone can write a code for this please


  2. #2
    scarecrowkid is offline Member
    Join Date
    Dec 2016
    Rep Power

    Default Re: Anyone can tell me this??

    Look into using a setter method inside the student class.

    That way you still adhere to the encapsulation convention that Java preaches.

    Java Code:
    public myClass{
    //some attributes
    private int studentID = 0;
    public void setID(int newID){ this.studentID = newID;}
    Last edited by scarecrowkid; 02-01-2017 at 08:00 PM.

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    The Netherlands
    Rep Power

    Default Re: Anyone can tell me this??

    Something tells me OP has used only static members so far because that works with a public static void main (String[] args)... :)
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts