Results 1 to 3 of 3

Thread: java

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Answers
    1

    Unhappy java

    some body please tell me the difference between class variable and instance variable...with a small example????


  2. #2
    Junior Member
    Join Date
    Jan 2014
    Answers
    2

    Re: java

    The same Class/Static variable will be shared by every object of that class whereas every object will have own copy of instance variable.


  3. #3
    Junior Member
    Join Date
    Oct 2014
    Answers
    1

    Re: java

    package org.sarvesh;
    public class A
    {
    static int x=0;//class variable
    int y=0; //instance variable
    public static void main(String args[])
    {
    A a1 = new A();
    A a2 = new A();
    a1.x = x + 5; //If we have 100 obj, all 100 obj maintain single copy of x
    a2.x = x + 5;
    System.out.println(x);


    a1.y = a1.y + 5; //if two objects are created we have 2 copies of y
    a2.y = a1.y + 5;
    System.out.println(a1.y+" "+a2.y);
    }
    }


  4.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact