Intuit Interview Question: What are the different uses o... | Glassdoor

Interview Question

Software Engineer Intern Interview

What are the different uses of the keyword "static"?

Answer

Interview Answer

1 Answer

0

You can use static for a field: and then it becomes class variable instead of instance variable. Which means, you can access it directly using class identifier.

{{{
class Person {
    int id;
    String name;
    static int groupID;
}

Person person = new Person();
System.out.println( person.id ); // instance variable access
System.out.println( person.name ); // instance variable access
System.out.println( Person.groupID ); // class variable access
}}}

Jay on Feb 24, 2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.