Jesper de Jong wrote:
If you don't understand exactly what the difference is between static and instance variables, then study Understanding Instance and Class Members in Oracle's Java Tutorials.
Jeff Verdegan wrote:
That's what "default" means. It means the value is there even if we don't explicitly set it.
Jeff Verdegan wrote:
No. I cannot explain it any more clearly than that. I don't know how to explain "the first time the class is used" more clearly than "the first time the class is used." If you did not understand that, I don't think there is anything I can say that you will understand.
And what part of it did you not understand anyway? You've been doing this the entire thread. Someone gives you a detailed explanation and you ask for more, but you don't provide any feedback and what you didn't understand. That makes it difficult to help you, and can lead to frustration for those who are trying to help.
Jesper de Jong wrote:Section 12.4 and 12.5 of the Java Language Specification explains exactly in what order things are initialized when a class is loaded and when an object is created. (Beware, the JLS is not always easy to read - but it is the definitive reference if you want to know exactly how Java works).
sekhar kiran wrote:
Myclass.java:9: <identifier> expected
System.out.println(obj.a);
^
Myclass.java:9: <identifier> expected
System.out.println(obj.a);
^
2 errors
sekhar kiran wrote:why there is no reply
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Jesper de Jong wrote:
sekhar kiran wrote:
Myclass.java:9: <identifier> expected
System.out.println(obj.a);
^
Myclass.java:9: <identifier> expected
System.out.println(obj.a);
^
2 errors
What do you think there is wrong with the code above? What do you think the error messages mean?
What's the purpose of the class AX? Why did you define it inside the main() method?
Winston Gutkowski wrote:
sekhar kiran wrote:why there is no reply
Perhaps because nobody has anything to say, or because we're getting a bit frustrated with the fact that, after over 100 posts, this thread doesn't seem to be going anywhere.
Anyway, we're all volunteers here, not your personal answer service; so please EaseUp (←click).
Winston
sekhar kiran wrote:i think this is your first post in this thread and even you didnt answer or reply to my post ,then why are you frustrated?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
sekhar kiran wrote:i think this is your first post in this thread and even you didnt answer or reply to my post ,then why are you frustrated?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
sekhar kiran wrote:i think we dont have to declare another class in main method,iam not understanding about error message,declaring class in a method which refere to local class so thats why i tried here
Winston Gutkowski wrote:
sekhar kiran wrote:i think this is your first post in this thread and even you didnt answer or reply to my post ,then why are you frustrated?
Because:
(a) Your reply shows just how much notice you take of responses (this is my 4th).
(b) What am I supposed to reply to? This thread has been meandering for the best part of a month; and I don't see any end in sight.
Why don't you simply state exactly what your problem is, and close threads when you get an answer?
Given the subject of this one, I can imagine it being open for as long as you've got "doubt in some program", which is NOT the intent of this site.
Winston
Jesper de Jong wrote:
sekhar kiran wrote:i think we dont have to declare another class in main method,iam not understanding about error message,declaring class in a method which refere to local class so thats why i tried here
Arbitrary statements, such as System.out.println(...), must always be in a method or constructor (or inside a static or instance initializer). You cannot put statements at class-level, which is what you were doing in your example. It doesn't matter that class AX is defined inside the main() method; the System.out.println(...) statement is not inside a method or constructor (or an initializer) in the AX class, so it's not allowed there.
sekhar kiran wrote:i got it,let me confirm is that local class which i defined inside the method?i execute code now
sekhar kiran wrote:class,static variable,static block,main method->checking constructor if it exists invoking instance block,constructor and method else execute the main method statements and terminate the program*/
Jesper de Jong wrote:
sekhar kiran wrote:class,static variable,static block,main method->checking constructor if it exists invoking instance block,constructor and method else execute the main method statements and terminate the program*/
I don't understand what you're trying to say here.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:When you run a program, it starts with the main method in the class you list.
From there, it all depends on what is in your main.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:I stand by my statement. You go to main() first, and then it depends. Example:
In this example, the print statement on line 7 executes first, and then the static block runs.
However, if you switch lines 7 and 8:
The static block runs first. But in both cases, you start with main, and depending on what is there, different things run.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:oops...sorry...you're talking about this?
I would suggest you try it yourself and see what happens.
Will Zelan wrote:
what is the output of the program
2)sorting array without third variable in below code i didnt understand logic anyone tell me
shyam sundar R wrote:Strings are immutable objects .. output will be pqr .
sekhar kiran wrote:i mean is this mandatory when you get the answer for one doubt then going to close the thread
i already mention title as doubts in program and technical question in java
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
sekhar kiran wrote:here i know it will execute first static block and goes to main method and print the statement,
ok i will say one example a program which consists of static variables,instance variables,static block,instance block,constructors,some methods and statements which order it execute sequence
Winston Gutkowski wrote:
sekhar kiran wrote:i mean is this mandatory when you get the answer for one doubt then going to close the thread
Pretty much: Yes.
You plainly haven't read the UseOneThreadPerQuestion (←click) page - or, for that matter, HowToAskQuestionsOnJavaRanch (←click).
Please do so now.
i already mention title as doubts in program and technical question in java
Hey, why stop there? Why not start a "Please tell me everything there is to know about Java" thread? You could keep that open for years.
Actually...don't.
Winston
Jeff Verdegan wrote:
sekhar kiran wrote:here i know it will execute first static block and goes to main method and print the statement,
Ok, so you understand order of execution then? Good.
ok i will say one example a program which consists of static variables,instance variables,static block,instance block,constructors,some methods and statements which order it execute sequence
If you want such an example, you can easily create it yourself.
Jeff Verdegan wrote:
sekhar kiran wrote:here i know it will execute first static block and goes to main method and print the statement,
Ok, so you understand order of execution then? Good.
ok i will say one example a program which consists of static variables,instance variables,static block,instance block,constructors,some methods and statements which order it execute sequence
If you want such an example, you can easily create it yourself.