Stanislava Trajlov

Greenhorn
+ Follow
since May 15, 2003
Merit badge: grant badges
For More
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 Stanislava Trajlov

I've passed it...
Do I have to explicitely ask for diplomma or are they (Sun) going to send it to my registered address?
Thanks
Stanislava
20 years ago
The last sentence in ASSERTIONS chapter in Java Certification book (pg 163):
"This example demonstrates that assertions are appropriate for checking preconditions in any method regardless of access, and for checking post-conditions in private methods."
Should it not be vice versa, ie:
...assertions are appropriate for checking postconditions in any method regardless of access, and for checking preconditions in private methods ?
Many thanks!
Stanislava
It helps, thank you both!
Stanislava
How do we handle cases when a class and its constructor aren't of the same accessability in JVM 1.4:
1) if the constructor has greater accessability than a class itself:
class AClass{
public AClass(){
}
}
or
class BClass{
protected BClass(){
}
}
2) if the constructor is less accessible than its class:
class CClass{
private CClass(){
}
}
or
public class DClass{
DClass(){
}
}
(there are more than 2 examples of constructor being less accessible than class).
What happens is we create:
- AClass() object from a class located in different package
- BClass() object from a class (other than its subclass) located in different package
- CClass() object from other class in the same package
- DClass() object from a class from different package ?
Do we get a compile error or run-time exception in JVM 1.4?
Is it always the more restricted of the two - class , constructor - that is taken into account?
Thank you!
Stanislava
Is JDK 1.4 compiler able to figure out if the wait()/notify() is
called in a non-synchronized section of the code?
Or is there a runtime exception thrown?
Thank you!
Stanislava
OK now I got the point... although I think this isn't necessary to know for the SCJP exam... but it's good knowing it.
Thank you guys!
Stanislava
Hi!
I was confused with the same mock exam question.
An exerpt from Java 1.4 Certification book (pg 123, Object Reference Casting section):
"...The rules for casting are broader than those for conversion. Some of these rules concern reference type and can be enforced by the compiler at compile time; other rules concern class and can be enforced only during execution.
...
When both OLDTYPE and NEWTYPE are classes, one class must be a subclass of the other."
It is the case we have here (Sub class is a subclass of Base class).
In the same section:
"Assuming that a desired cast survives compilation, a second check must occur at RUNTIME. The second check determines whether the class of the object being cast is compatible with the new type...
Here, COMPATIBLE means that the class can be converted according to the conversion rules...:
If NEWTYPE is a class, the class of the expression being converted must be NEWTYPE or must inherit from NEWTYPE."
The case we have here is:
NEWTYPE is Sub, OLDTYPE is Base.
Base doesn't inherit from Sub
nor is the Base class equal to Sub class
BUT Base and Sub classes' implementation is THE SAME.
For me it's not logical that the latter runtime check isn't enough to get error free program run (as Dan said) - but I guess there are things we just have to accept even though they aren't too logical
Why does compiler not "filter out" this case (base class to subclass cast) if we are going to get runtime exception anyway??
I hope I'm not too confusing :roll:
Thank You very much!!!
Stasha
I thought static methods could be overriden until I read this:
http://java.sun.com/docs/books/tutorial/java/javaOO/override.html :
...a subclass cannot override methods that are declared static in the superclass. In other words, a subclass cannot OVERRIDE a class method. A subclass can HIDE a static method in the superclass by declaring a static method in the subclass with the same signature as the static method in the superclass..."

What is the difference between HIDING and OVERRIDING methods?
In both cases we need to have the same signature - the same argument(s) and return type so I see no difference.
Could someone explain this to me.
Thank you!
Stasha
Thank you all for the help!
Stanislava
OK, so all of the following wrapper classes: Boolean, String, Double, Integer, Float, Byte, Short and Long DO OVERRIDE Object's equals() method (and therefore do "deep" comparios) while it's ONLY StringBuffer class that doesn't override it and for StringBuffer objects equals() and == have the same effect.
Is that right?
Thanks!!!
I thought equals() method was overriden (ie. was performing "deep" comparison) only in String and Boolean wrapper classes.
Now I encountered an example in Poddar Questions where Double seems to overriding equals() as well...
What is finally the list of all wrapper classes overriding Object's equals() method?
Thank you!!
String s1 = "Hello";
String s2 = "Hello";
String s3 = new String("Hello");
String s4 = new String ("Hello");
s1 and s2 point the same object (object A).
s3 and s4 point 2 different objects.
Does s3 point the same object as s1 and s2 (object A)?
--------------------------------------------------
If the order was different:
String s3 = new String("Hello");
String s4 = new String ("Hello");
String s1 = "Hello";
String s2 = "Hello";
Again s3 and s4 point 2 different objects (object A and object B respectively).
And s1 and s2 point same string object, but which object are s1 and s2 pointing at? A or B?
Many thanks!
Stasha