Nain Hwu

Ranch Hand
+ Follow
since Sep 16, 2001
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
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Nain Hwu

Mike,
Short arguments in a method invokation are converted to
int. See JLS 5.3
Andre,
Only b & e are true. We need to clarify the terminology here.
I assume top-level nested class means "static" nested class
per JLS.
a) is false, since top-level nested class, i.e static nested
class has no enclosing instance, just like any non nested
top level class.
b) is true. In fact, it can have both static and non-static
member variables.
c) is false, because member variable in an interface is
implicitly "static". In fact, they are public static final.
d) is false, for the same reason as a
e) is true, for obvious reason.
[This message has been edited by Nain Hwu (edited December 13, 2001).]
Binkie,
Even though you put the classes in different directories, they are still in the same package, the default package, since
you did not specify package for your classes.
So, it will compile.
[This message has been edited by Nain Hwu (edited December 10, 2001).]
Neha,

Inside a class, only following are allowed:
- members
- instance and static intializers
- constructors
See JLS chapter 8 for details.
So, a statement like System.out.println(c); is not
allowed. Put it inside a method or a
initializer block will work.
[This message has been edited by Nain Hwu (edited December 10, 2001).]
[This message has been edited by Nain Hwu (edited December 10, 2001).]
Tony,
Just think why it is called "anonymous"?
It has no name and a constructor must have the same name as
its class. So, it is impossible to have a constructor for an anonymous class.
Jason,
Yes, according to API, charAt() should return a char,
not a Character object.
Neha,

There are lots of free tutorials. Here is
one
I also recommend the book "A Programmer's Guide to java Certification" by Khalid & Rolf. It has an excellent chapter on inner class.
[This message has been edited by Nain Hwu (edited December 09, 2001).]
Neha,


i am not following how Q3 works.
because if i compile the above code i am getting undefined variable B.


As Marilyn mentioned earlier, all classes defined in an interface
are implicitly static. Their names/types are constructed
by prefixing the types with the name of the enclosing class names.
For instance, the name for class A in interface B of question 3
is actually B.A.
The correct way and the only way to instantiate a static class is by "unqualified" instance creation expression, i.e.
without an expression in front of the "new" operator.
So, I think the statement B.new A() should be changed to:
new B.A();
Give it a try and you will see it compiles.
[This message has been edited by Nain Hwu (edited December 09, 2001).]
[This message has been edited by Nain Hwu (edited December 09, 2001).]
Matthew,
That's the design of the java language.
The only modifier allowed for local variable is final.
16 years ago
Mathhew,
You are right - instanceOf does not exist in java language.
16 years ago
Hi, Manfred,


Don't confuse access modifiers with compiler checks. All methods
regardless of access modifiers are inherited by subclasses


I have to disagree with you on this. If a method is not accessible, it is not inherited. See JLS 8.4.6.
For example, a private method is not inherited.
And Jehred's question is another example.
Contrary to what you said, I got different result from
following code. They compiled and ran just fine.

16 years ago
Jared,
I agree with you.
16 years ago
Not in my test taken in 11/20.
I have serious doubt that the test will go beyond the objectives,
which do not include SWING.
Hades,
String object is immutable, i.e. not changable.
Any String method that needs to change the contents
will create a new String and return a reference to the
new String. If there is no change, a reference to the original
String is returned.
Whatever the case is, your code
simply has no effect on 's'.
[This message has been edited by Nain Hwu (edited December 04, 2001).]
Fengqaio,
I got this response:
Main method not public.