CrazyEngineers
  • Java: Is "reference variable of a class" same as "an object of that class"?

    pratap singh, upendra

    pratap singh, upendra

    @pratap-singh-6xlmve
    Updated: Oct 26, 2024
    Views: 1.7K
    In context to Java programming,

    Is "reference variable of a class" same as "an object of that class"?

    Also for a code like

    class Sample
    {
    int a, b;
    public static void main(String arg[])
    {
    int c;
    // other statements
    }
    }

    Among the variables a,b, c which are the class variables.

    Is there a difference between variable a/b and variable c as far as their scope is concerned?
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Anoop Kumar

    MemberFeb 18, 2016

    I assume you like to know the difference between, Instance variable and local variable.

    There is certainly scope difference between variable "a" and "c".
    "a/b" are class/instance variables .
    "c" is a local variable defined inside the method.
    scope of "a/b" is associated to instance of class, object, just like method, in your program main() method.
    Better go through full tutorial of varial type and do some practice.
    <a href="https://www.tutorialspoint.com/java/java_variable_types.htm" target="_blank" rel="nofollow noopener noreferrer">Java - Variable Types</a>

    You question is confusing, what exactly you are looking far?
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register