Mafalda Alabort

+ Follow
since Mar 02, 2001
Merit badge: grant badges
For More
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 Mafalda Alabort

Hi all,
I passed the programmer's exam this morning and just wanted to thank everybody who makes this site or participates in the forums. You have been a great help.
The questions on threads were really nasty but I found the questions on java.lang and java.awt are not hard and you can answer them quickly without having to look through loads of code.
Good luck to all the aspirants.
23 years ago
cannot you create an instance of the static inner class (or top level nested class) as
OuterClass.InnerClass inner = new OuterClass.InnerClass() ?
If you look in the API those methods are called asin(), acos() and atan() all in lowercase.
I hope they dont ask questions like this in the exam.
Question 49 in exam Bonus 1 says:

Consider the following class definition:
public class Parent {
final void zzz() { }
Which of the following methods may appear in a subclass of Parent, when the subclass is in a different package from Parent?

The option A) void zzz() { } is given as wrong.
I know final methods cannot be overriden, but these two source files compiled successfully:
package p1;
public class X{
final void aMethod(){}
package p2;
import p1.X;
public class Y extends X{
void aMethod(){}
I supose it compiled because class Y cannot see aMethod() in X. It is the same as when I can declare a method with the same name and argument list that another final and private one in a superclas. Please correct me if I am wrong.
And shouldn't answer A be given as correct then?
Thank you
[This message has been edited by Mafalda Alabort (edited March 25, 2001).]
[This message has been edited by Mafalda Alabort (edited March 25, 2001).]
when timeout expires the thread moves to the seeking lock state.
It explicitly says so in the Java 2 Certification Study Guide.
I hope it helps.
I think initialization occurs on constructor invocation, after execution of the superclass constructor and before execution of the body of the constructor itself.
Please correct me if I am wrong.
Hi Nitin,
int i= 3;
we can put it as i=i*(2+i++)
then first evaluate and then asign
if we did
then i would be 18

[This message has been edited by Mafalda Alabort (edited March 24, 2001).]
When an overloaded method gets called, the compiler chooses the one with the same argument type as the argument in the call.
But what if the argument of the method call doesn'nt exactly match the arg type of any of the methods, but can be converted to match the argument type in more than one method. Which one does the compiler choose? Does it choose the closest one in the conversion chain?
Here is an example:
public class OverLoad{
public void aMethod(int i){
System.out.println("int version : " +i);
public void aMethod(long l){
System.out.println("long version : " +l);
public static void main(String [] args){
byte b = 2;
OverLoad ol = new OverLoad();
The output is "int version : 2"
Why exactly is it choosing aMethod(int i) ?
Thank you.

[This message has been edited by Mafalda Alabort (edited March 24, 2001).]
Thank you Bala and Huiying
I compiled and run this code. It seems that 100.0/-0 s positive and 100.0/-0.0 is negative. So there is a negative zero for doubles but not for ints?. Is there any explanation for this?
public class A1{
public static void main(String [] buff){
//double d = 100.0/-0.0; // outputs negative infinity
double d = 100.0/-0; // outputs positive infinity
if(d == Double.NEGATIVE_INFINITY){
Thank you very much
When you override a method, the overriding method cannot throw any checked exception not thrown by the overriden one.
So if a method m() in class Super throws a IOException and we override m() in class Sub that extends Super, then if m() in Sub declares that throws any checked exception, they have to be IOException or a subclass of it.
So the method in Sub3 is ok

A constructor will call the no arguments constructor in the superclass, so you'll get the compile error because dont have access to it.
You didn't define any constructors in B, but the compiler will still generate one.
This code will compile as you explicitly call another (non private) constructor:
class A{
private A(){}
A(int i){}
public class B extends A{
Hope it helps
[This message has been edited by Mafalda Alabort (edited March 21, 2001).]
It should'nt give you an error as you are dividing by 2 and not 0.
In the second question, the code first checks whether the object is an instance of C, if this is true it means that the object was created by instantiating class C or any of its subclasses (class D). So then it checks whether it is not an instance of D.
Hi all,
The narrowing conversion would normally not be allowed without a explicit cast. The exception is when we assign a literal to a variable. In this case the compiler calculates the target's size and "implicitly casts" the literal i fhere is enougth room in the target.
It is exactly the same as when you do:
byte b = 40; // this is ok
byte b = 4000; // compile error : possible loss of precission
Both 40 and 4000 are of size int. The compiler checks that 40 could be represented by a byte and automatically casts it.
I know I am not being very clear, but I hope it still helps.

if you want to use the static vbles x and y, do not declare them again inside main().
When you say "int x =" you are declaring a new vble local to the method. If you get rid of "int" inside the main() method, the code will work:
public class A{
static int x=10;
static int y=10;
public static void main(String[]args){
x=x++ + y++;
I think.