The pathname must begin with a "/" and is interpreted as relative to the current context root
. So you have to override with static method only. But in this case, it is called Hiding (continue reading section JLS8.4.6.2).A compile-time error occurs if an instance method overrides a static method.
JLS11.3 Handling of an exception
If a try or catch block in a try-finally or try-catch-finally statement completes abruptly, then the finally clause is executed during propagation of the exception, even if no matching catch clause is ultimately found. If a finally clause is executed because of abrupt completion of a try block and the finally clause itself completes abruptly, then the reason for the abrupt completion of the try block is discarded and the new reason for abrupt completion is propagated from there.
So, to add a String to the pool, you intern it. Now, if you intern object S, ABC will be added to the pool (assuming new doesn't add ABC to pool when you initialize S).When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.
If this true, Prashanth and others, I agree answer to the original post would be 1(one). WHY WOULD I EVER NEED TO INTERN A STRING??? just to get a reference from the pool??? Why would API state "Otherwise, this String object is added to the pool and a reference to this String object is returned" ? The string would already be in the pool!!!For the exam, you need to know that IF you use 'new' to create a new String that is not *already* in the pool, TWO String objects are created. But there is no need to ever have duplicates in the String pool, so if the String is already in the pool at the time you use 'new', there will be only ONE created.
Originally posted by Shan:
With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running
JLS 12.8 Program Exit
A program terminates all its activity and exits when one of two things happens:
* All the threads that are not daemon threads terminate.
* Some thread invokes the exit method of class Runtime or class System and the exit operation is not forbidden by the security manager.
b) I am using Jcreator as an IDE. If I use the compile file and execute file options, the program executes. If I use cmd line on Windows
java test (with test in java sdk's bin)
I get an exception
Exception in thread "main" java.lang.NoSuchMethodError: main
The question is "using new alone, would JVM place the literal in the pool"? Does new create two String objects?snippet from Kathy's book
2 � String s = new String("abc"); // creates two objects, and one
// reference variable
In this case, because we used the new keyword, Java will create a new String
object in normal (nonpool) memory, and s will refer to it. In addition, the literal
�abc� will be placed in the pool.
This is what I have been assuming, till I encountered this original post. I think this is true and there is errata in the book. If not, we need to be enlightned, with new operator creating two objects.John Paverd response:
The new operator only creates 1 String object.
I dont disagree with this at all.John Paverd response:
String s1 = "abc";
String s2 = new String("abc");
System.out.println(s1 == s2);
When new String("abc") is executed, Java creates a copy of the "abc" String that is in the literal pool. If that were not so, the preceding code would print true. Run it and you will see that it prints false. False means that s1 and s2 refer to 2 different objects, so there must exist two String objects containing "abc".