Cristina Vinuela

Greenhorn
+ Follow
since Dec 12, 2005
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 Cristina Vinuela

Hi!

But the loop can access the method variables, that's why the compiler finds two i variables IN the loop, the local one and the method one.

Hope it helps

Cris
Hi,

The instanceof operator returns true when the first operand is not null and it can be casted to a type of the second operand without throwing a ClassCastException.

If the first operand is null and it can be casted to a type of the second operand without throwing a ClassCastException, instanceof returns false.

If the first operand cannot be casted to a type of the second operand without throwing a ClassCastException, there is a compile-time error.

Here it is an example,

class Point { int x, y; }
class Element { int atomicNumber; }
class Element2 extends Element{}
public class ClsPruebas1 {


public static void main(String[] args) {
Point p = new Point();
Element e = new Element();

Element2 e2=new Element2();
Element2 e3=null;

System.out.println(e2 instanceof Element); //returns true
System.out.println(e3 instanceof Element); //returns false
System.out.println(e3 instanceof Point); //compiler-time error
}

}

Hope it helps,

Cristina
Hi,

I think 1 Object as well.

In C c1=new C(); we have vble c1 ----> object C 1

When we call m1, we have a copy of c1 in ob1, because parameters are passed-by-value in java. So, c1,ob1-----> object C 1

In ob1 =new C(); we assign a new object to ob1.
c1------>object C 1
ob1----->object C 2

In C c2=m1(c1); we assign c2 to the object pointed by ob1 in m1, and ob1 doesn't exist anymore because we are out of m1.
c1------>object C 1
c2----->object C 2

C c3=new C(); is easy
c1------>object C 1
c2----->object C 2
c3----->object C 3
In c2=c3 we assign the object pointed by c3 to c2
c1------>object C 1
object C 2
c2,c3----->object C 3

So, in line 6, there is only one object which is not being referenced (object C 2) and it's eligible for garbage collection.
Hi,

The single & evaluates both operands regardless of the result of the first one. So, if a == null when it evaluates a.length() a NullPointerException is thrown.

The && only evaluates the second operand if the first one is true, because if it is false the whole expression is false, so it doesn't go on, that is why it is called a shortcircuit operator.

Hope that helps

Cris
Hi,

When you say that the "local class is implicitly static", it means it cannot access instance variables or methods of the outer class. So the "super" or "this" you are not allowed to use are the ones of the Outer class (TopLevel.this or TopLevel.super).Those would give a compiler error.

If you write "this" in the inner class, it refers to the instance of the inner class. It is something like the inner class is static towards the outer class, not towards itself.

Hope that helps

Cris