Win a copy of Rust Web Development this week in the Other Languages forum!


+ Follow
since Aug 18, 2000
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by yanish

Which of the following statements are true
1) constructors cannot be overloaded
2) constructors cannot be overridden
3) a constructor can return a primitive or an object reference
4) constructor invocation occurs from the current class up the hierarchy to the ancestor class
I think that 4) is true also.
As I know, class's constructors always call the superclass's constructor (explicitly or implicitly). So, if you have class
Base and a SubBase class extends Base, the code like
SubBase sb = new SubBase(); will invoke super's constructor and then further up. Markus advises to print smth from the constructors to see what is an order of invocations. But, anyway the first line of any constructor should invoke super's constructor (the compiler does it if you missed it). It means that invocation goes up only. Just an example

No one argues about an order of printed lines
1) b method
2) a method
But, the matter is that aMethod invokes bMethod but not conversely.

A parent class has a default constructor which throws IOException. But as the sub class has no any defined constructors, the compiler creates a default one but without the 'throws' clause. As parent's constructor throws a checked exception, it's needed to handle it correctly. You can do it by placing 'throws' clause in constructor definition or by using the 'try-catch' block. But created by the compiler default constructor does neither.
You can look at:
Some related discussion is there.
Mapraputa's idea is completely correct. A main point here is that a default constructor has been defined with package accessibility. So, there are no any ways to instantiate the class (or extend the class) outside the package where it is defined.
22. If you want subclasses to access, but not to override a superclass member method, what keyword should precede the name of the superclass method? (Fill in blank).
I wrote: super but the MindQ says it's wrong.
Was I wrong?
Deepak, Ajith
thank you for your explanations.
Although I can't find a good reason why the Java Specification imposes such restriction on using of anonimous classes, I take it as it's designed.
But especially I like the compiler's error message:
A default constructor cannot be created for this class because the constructor of its superclass throws the exception Define the constructor for this class explicitly.
Unfortunately, I can't test it in jdk1.3
Can anybody explain what's wrong here:


Thank you in advance.
According to Bill Brogden's "Exam Cram":
"Java has four basic types of primitives: integer, character types, floating-point types, and boolean types.
The integer types are all treated as signed ... The character type represents 16-bit Unicode characters and can be considered as unsigned integer for many purposes."
In Marcus Green's tutorial four integer types of primitives are:
byte, short, int, and long only.
I would not choose a char for the answer.
I think the question is a little bit ambiguous. The Container has a method inherited from Component add(PopupMenu). In terms of ineritance the PopupMenu is a Menu.
You just need to know when the String's functions return the same reference (without creating new one). As usual it's the case when nothing has to be changed (i.e. "str".trim() nothing to trim, so in that case "str" == "str".trim();
"str".toLowerCase()== "str"; TRUE
"str".replace("a", "c") == "str"; TRUE
"str".concat("") == str; TRUE and so on.
String's toString() method returns always the same reference, so
"string" == "string".toString(); always TRUE.
For the case of "string" == "str" + "ing"; (TRUE) I have not a good explanation but I found that "+" works quasi the JVM sees the whole word at once.
So, "s" + "t" + "r" + "i" + "n" + "g" == "string" always TRUE.
I think you know why "string" == "string" (from a pool of String literals).
I agree with you that it's not a good way of coding, but nothing forbids you to have a method with a capitalized name.
compiles and runs perfect.
I'm sorry guys, but what does you mean by saying "For the purposes of the exam"?
The question is "Which of the following are correct?". So, my understanding is what are the correct methods declarations?
So, all the four answers are correct.
public static void Main(String args[]) is completely correct declaration.
the default modifiers for any interface are always public (for fields and methods).
Moreover, interface methods can't be native, static, synchronized, final, private, or protected.
you forgot an abstract modifier.
The first statement is definitely false.
The daemon threads serve to provide a service in the background.
They live as long as the program lives (at least one non-daemon thread). But their death do not influence the running program.
So, any unchecked exceptions thrown by daemon threads will never quit the JVM.
The second statement is false too. According to "Thinking in Java" by Bruce Eckel:
"Each Thread �registers� itself so there is actually a reference to it someplace and the garbage collector can�t clean it up."
I'm sorry, but why does everybody say that setbounds() is a method of the Component? or it's just a typo.