Skip to main content

Class vs Instance vraiable

1 reply [Last post]
Joined: 2008-08-16
Points: 0


Having learned Java is clean and simple object-oriented language (OOL), but powerful; I've started learning Java by doing tutorial from Sun web site.

In doing exercise, I'm really confused on a question about the field/variable, class/instance variable

One of a nice feature of OOL is to hide detailed implementation and let programmer focus on algorithm to solve problem, rather than the code implementation.

I'd really appreciate to an explanation about why we care about the difference between class/instance variable and in what way this info does help programmer in coding to solve their problem


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-09-24
Points: 0

Hi there,
I'll try to answer your question first with a quick summary of what I think your question is:

Q: You want to know the different between a "class" and an "instance variable" ?

A: A class is a definition and an "instance variable" (aka instantiation) is the realization of a class in a program.

So, to give an example, I have a class called "school", it defines what a "school" is to me (such as a school suited for my needs would include an address, number of students, school name). In my program, I can instantiate the school class for actual schools that I deal with, e.g. Hometown High School, City College, etc. these are instantiations or "instance variables".

I hope this is helpful to you.