Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide
this week in the
Programmer Certification
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Programmer Certification (OCPJP)
forward referencing
rani bedi
Ranch Hand
Posts: 358
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can anyone explain me why Test2 runs fine where as Test1 gives a compile time error about forward referencing?
public class Test1 { private int i = j; // compile time error private int j = 10; public static void main(String args[]) { System.out.println((new AQuestion()).i); } }
public class Test2 { private int i = giveMeJ(); private int j = 10; private int giveMeJ() { return j; } public static void main(String args[]) { System.out.println((new AQuestion()).i); } }
Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
Anupam Sinha
Ranch Hand
Posts: 1090
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Parmeet
A few hours before we were discussing the same hing. Check out
this
thread
.
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Variable initialization
please explain why the compiler is not complaining and why the output is 0
forward refrerences
Forward Referencing
about forward refrencing
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...