![]() |
Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
Your program cannot compile because using algorithm of definitive assignment Java makes sure at compile time that each variable which is being used has been initialized ( I mean has a value. Note that I am saying each variable used. It means you can declare a variable but when you try to use its value then only it is a problem if you haven't assigned any value to it or it has not been implicitly assigned a value as in case of instance variable. ) . You just declared a reference variable "a" of type one as in If you don;t want to do that then just to compile your program you can just declare one a ; as the instance variable of class three ( here you will have to declare static one a ; because you are using it in main ( ) method which is static ). Becuase each reference instance/class variables are initialized to null by default your program will compile but in display method it will throw NullPOinterException. static void main(String args[]){
Replies: |
Sponsored Links
|