Edmen Tay

Ranch Hand
+ Follow
since Oct 21, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Edmen Tay

Hi All,

Firstly, I would like to thanks all of the experts in javaranch and this forum which provide me a lot of explosure in java and assistant in Mock test question. Thanks you all!! your help is much more appreciated.

I was so busy on work recently and only took this few holiday to do short mock test + practical. I did not passed the test with good score and only 68%. But I will continue to improve my java skillset. Anyone can advise what step shall I further?

Last but not least, Thanks all very much!!

Sincerely
Edmen Tay
15 years ago
Yes, is not "does not compile". I am sorry that I had mistaken.


The instance initializer block in the first example -- the one that tries to print "SCEA" -- will only be called if an instance of the class is created. Instance initializers run at the beginning of each constructor, immediately after any superclass constructors. In the "maClass" example, no instance of maClass is ever constructed -- i.e., there's no "new maClass()" anywhere -- so that initializer is never invoked.



I got it.

Many thanks.

Regards,
Edmen
Hi All,
I got this question from Devaka Exam Lab (Final):



the output is "SCJP, Mobile Application Developer, null"

But, I had tried this in IDE,



The output is "41236577123657". The initialization block is compiled.

I just wonder why the initialization block does not compile? please help.

Many thanks,

Regards,
Edmen
Hi All, I got this question from enthuware mock test:




variable "i" is declare as protected. how can class B cannot access "i"? please help. :roll:

regards,
Edmen
Hi,
When the program run,

Menum m1 = Menum.A;

Compiler will run constructor A(5) and then call,


and the same do for,

Menum m2 = Menum.B;
Menum m3 = Menum.C;

When calling a method floor(); compile will assign an int value to variable std. So,

variable std in m1 is 5
variable std in m2 is 30

Note, There is not method floor() in enum C(5), but floor(int y). Then compiler will look for the method in Menum which assigns 1 to variable std for m3.

This is the method of overriding and polymorphism in Java compiler.

Therefore, you will get output:
5
5
5
[5] [30] [1]

Please correct if i am wrong, Hope this help.

Edmen


String s1="ram";//creates a new object of class String, and assigns it to the reference variable s1.

String s1=new String("ram")//creates a new object of class String, and assigns it to the reference variable s1.



if,
String s1 = new String();// "" assigns to the reference variable s1
just like
String s1 = "";

Strings is final class and it is Immutable Objects. you can read more on String, StringBuilder, and StringBuffer.

Hope this help.

Regards,
Edmen
Ok, I got it. Thanks for the prompt reply.

Edmen
Hi all, this question from Enthuware SCJP5 Mock Test. I had tried the code in IDE below,



I hit compile error at line 10, then I explicitly declare constructor "SuperClass(){}" in SuperClass. It work fine.

Is it because of explicit declare of constructor with parameter argument in super class will need to declare constructor with no argument as well?

Can anyone help?

Many Thanks.

Edmen
Hi Punit,

Integer c = new Integer(128);
Integer d = new Integer(128);
System.out.println(c.equals(d));



It is true.

Integer MAX VALUE is 2147483647 and MIN VALUE is -2147483648

Edmen
Alright, I think i got what you trying to meant.

for array, it is not overriden and it will run,

for wrapper class, it will be overriden and will run,


Please correct if i am wrong.

Many thanks.

Edmen.
Hi, My question from Inquisition (SCJP5 quiz by Mark Dechamps).


The answer is false. Can anyone explain?

When I try,


Many thanks,

Edmen.
Alright, I am mistaken the initialization block and constructor.

I am understand now.

Thanks Abhi.

Regards,
Edmen
Hi, my query is from SCJP5 quiz by Mark Dechamps:



Answer is 1 and 3.

line 3 because of semicolon.

But, I don't understand why line 1 will not compile. Is it constructor cannot be synchronized?

Can anyone help.

Many Thanks.

Regards,
Edmen
Hi,
Below is the left out part:

lst5.add(new Object());//will not compile as it is unknown type of subclass AA


Regards,
Edmen
Hi all,
I try to understand the below code in IDE. and put some of my understanding comment


Please correct if i am wrong.

Thank you

Regards,
Edmen