|
Well, first of all you need to declare the variable "show" to be of some class, so the compiler knows what it is. "show = new Student()" doesn't do that, although you could add some "implicit declaration" to Java to say that if "show" hasn't already been declared, then this statement declares it implicitly. However, there are some cases where you would want to do something like "X vbl = new Y()". I've done it myself. I have several methods that produce a List of objects. Now, List is a (Java 2) interface that can be implemented in different ways (ArrayList, LinkedList,...). Usually my methods use an ArrayList, but I might want to change that in the future. So, I have code like this: public List getData(...) { List result = new ArrayList(); ... return result; } Doing that minimizes the changes I'd have to make if I wanted to use a LinkedList instead. There are more complex situations; I've just acquired a bunch of code that sends commands to a server over RMI, and it's loaded with interfaces and code like that. PC2 -----Original Message----- From: Stone, Brad V (TC) [mailto:bvstone@taylorcorp.com] Sent: February 7, 2001 07:57 To: 'JAVA400-L@midrange.com' Subject: RE: Instantiation question I'll let others answer you question, but I'd like to expand on your question. Why do you need to say: Student show = new Student(); Why not just: show = new Student(); Is there a case where you would want to do something like: Student show = new Principal(); or Principal show = new Student(); Maybe the answer to your original question will answer mine. :) I've always thought that this type of declaration was a bit redundant. Brad +--- | This is the JAVA/400 Mailing List! | To submit a new message, send your mail to JAVA400-L@midrange.com. | To subscribe to this list send email to JAVA400-L-SUB@midrange.com. | To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com. | Questions should be directed to the list owner: joe@zappie.net +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.