By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,248 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,248 IT Pros & Developers. It's quick & easy.

Differences between defined variables

P: 3
I created class and define three kind of variables. What are the differences among them?
Public Static String c1,
Static String c2,
String c3?
4 Weeks Ago #1

✓ answered by dev7060

String is a non-primitive data type used to store array of characters.

Static is a keyword used to fulfill common requirements. We make something static when it's common to all the objects. Static variables take memory in the class area at the time of class loading.

Public is an access specifier which allows other classes to use that data member.

String c3 -> Just a String type instance data member which can be used through an object.

Static String c2 -> A static (non-instance) data member of String data type. Static members can be accessed directly without creating an object.

Public Static String c1 -> A static (non-instance) data member of String data type belonging to class A (let) having public accessibility. In other classes, you can use this data member by creating an object of class A. Also, since this member is static, it can also be accessed directly as A.c1 in other classes.

Share this Question
Share on Google+
2 Replies


dev7060
P: 77
String is a non-primitive data type used to store array of characters.

Static is a keyword used to fulfill common requirements. We make something static when it's common to all the objects. Static variables take memory in the class area at the time of class loading.

Public is an access specifier which allows other classes to use that data member.

String c3 -> Just a String type instance data member which can be used through an object.

Static String c2 -> A static (non-instance) data member of String data type. Static members can be accessed directly without creating an object.

Public Static String c1 -> A static (non-instance) data member of String data type belonging to class A (let) having public accessibility. In other classes, you can use this data member by creating an object of class A. Also, since this member is static, it can also be accessed directly as A.c1 in other classes.
3 Weeks Ago #2

P: 3
Clearly explanation ! Great Thanks a lot !
3 Weeks Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.