Variables
Both Java and C# are strongly typed languages, meaning variables must be declared with a specific type before they are used and can hold only values compatible with that declared type. Both Java and C# define seven types of variables. Despite this coincidence, significant differences exist in how each language categorizes its variable types, as described in Table 5-20.
Table 5-20. A Comparison of Variable Types in Java and C#
Java | C# | Includes |
|---|---|---|
class variable | static variable | Fields declared using the static modifier. In Java, this also includes any fields declared in interfaces. Refer to the Members section earlier in this chapter for full details. |
instance variable | instance variable | Fields declared as members of a class (or struct in C#) that are ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access