Thomas Drew

Ranch Hand
+ Follow
since Sep 15, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Thomas Drew

Exception should be considered checked. Only runtime exception are unchecked.
If you try to use a varible in your code before you declare it you will get an compile error.

declaring the code

foo = "here is a string";
String foo= new String();

will give you a complie error you can not create forward reference in this manner.
There is really no way of telling which thread finished first. Since the num is static both threads are updating the same value. So, When num is incremented to 9 the loop exit on both threads.
pravin kumar
Here is a short program to explain what is happing it it helps.




The output of the code is :

-33 = 11111111111111111111111111011111
After Conversion ~-33 = 100000
- 8 = 11111111111111111111111111111000
Remember only the last 5 digits are used for -33 shift whick is 0
Results of a>>>b :=-8 >>> 0 = -8
Akshay , you are overriding the op option in MathOpt. The Op in MathOpt does not throw an exception. Where as the option in Math does. To fix the problem you will have to either throw the exception in the MathOpt class, remove the statement from the try block, or call the op option in the super class. If you elect to have the class throw an exception you will have to change the class Mathopt to throw an exception as well.
Hope this helps.
I've never used this but found the page while searching the internet maybe it can help.

excel api
16 years ago
sunitha , Here is another example to show the order of how static and instance initilizer are executed. This example extends a class and print the order in which static, instance initilizer, and constructor are executed.

output of the program is :


Static test1 initilizer is executing
Static test2 initilizer is executing

Test1 instance initilizer is executing
Constructor test1 is executing

Instance initilizer test2 is executing
Constructor for test2 is executing




Heres the program.
Hope this help you. Thomas
Sorry, I left out the print method for the test1 class. here it is :
Sunitha, Here is what the java Specification say about initilization of instance and static blocks.


8.6 Instance Initializers
An instance initializer declared in a class is executed when an instance of the class
is created (�15.9), as specified in �8.8.7.1.
InstanceInitializer:

8.7 Static Initializers
Any static initializers declared in a class are executed when the class is initialized
and, together with any field initializers (�8.3.2) for class variables, may be used to
initialize the class variables of the class (�12.4).




This came from the pdf version if you want to read it.


Also, all the varibles you declared in the static and instance initalizers have scope only within the block of the initalizer. In other words all the varibles you create in your examples can't be used outside of the block where you created them. example:
The following code will print 0 not 23. This because the foo varible declared in the initilizer block is a differnt varible then the one declared in the test1 class. Hoped this helped.





Andreas
In your constructor Main(float i) you pass the float value for i in but you never assign it to anything. The this() call your constructor with no arguments which is always going to assign the value 3 to i.
srikanth
I could not find any examples of a class created inside an interface. I used the code below to see how it would work. Prehaps someone else has more insight into this.



this code compiled and ran fine . So for your questions :
1)it is not possible in the java Laungage.
false, I was able to implement the class in the interface.

2)The class is always public.
not sure but I thank the answer is true
3)The class is always static.
false
4)the class methods cannot call the methods declared in the interface.
false

5)the class methods can call only the static methods declared in the interface
false


another problem I had with the class in the interface is that the tryit method could not be declared abstract. I assumed the class it self would be abstract since it was in the interface but trying to set the methods in the class to abstract generated an error.

hope this help.
Roel this is wrong.


protected: if a member is protected, it's accessible to all classes in the same package (doesn't matter of it is a subclass or not)



for a class to access a protected member of another class it has to be a child of that class. Even if two class are in the same package, if class B isn't inherited from class A class B will not be able to access any protected members of class A.
Here a short program to illustrate what Sandeep is saying.





results of running program:

MIN_VALUE FOR int a = 10000000000000000000000000000000 or -2147483648
Two Complements of a =1111111111111111111111111111111 or 2147483647
Two Complements + 1 a = 10000000000000000000000000000000 or -2147483648
srikanth
invocation means that you are calling the code inorder to execute the code. Constructors do indeed call the constructors of their parent classes before excuting their own constructor. so all the constructors in the ancestor classes are called before before the current object constructor.
srikanth
You are correct that you don't have to set references to null. I thank they were tring to say that garbage collection occurs when there are no longer any vaild reference pointing to the object. This can occur for reason other then setting the reference to null.