Win a copy of Microservices Testing (Live Project) this week in the Spring forum!

Mo Bustany

Greenhorn
+ Follow
since Feb 03, 2003
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 Mo Bustany

I've seen abstract static classes being used an first level inner classes.
1. Is that the only purpose for them? What do you
buy by defining it static other than not having
an inner class per top class instance. And why is
it abstract???
2. Is there a purpose of defining a top level abstract static class?
Thank you
18 years ago
Page 150 of Sun Cert. by Sierra and Bates states that we get the cast from int to short for free.
short s2 = 0x7fff;
works but not this one:
short s1 = 0x8000;
Here is the code and the output, both print the subclass

Given the following

Why isn't s1 identical to s4 but s2 is identical to s1!!!
I declared a 2-dim array of strings as final. However, I'm able to modify the contents of the array.
1. Why??
2. How can I make the contents final?
Thank you


[ Jess adjusted the line breaks so the page won't scroll horizontally ]
[ February 06, 2003: Message edited by: Jessica Sant ]
Barry, could you tell me what java 'rule' does my original code violates?? It looks to me it's syntactically correct.
I wholeheartedly concur. javaranch.com is a blessing and the kathy/bert book is great.
Here is the parent class (inner class).

And here is the subclass (in a different package.

I get the error:

What does it mean 'not in scope'!!!
[ Jess adjusted line break in the code so the page won't overflow ]
[ February 06, 2003: Message edited by: Jessica Sant ]
Yep, Francisco A Guimaraes' answer is the most valid. the Instances of A,B and C are assigned to variable of type A. So only A methods can be seen. The other m1 methods are distinctly different from the signature of m1 of A so they are never seen. PLEASE NOTE: Try this test, define a public member int variable, mVar in each of the three classes and assigned them different int values. Then use a1,a2,a3 to display them. You will get a surprising result. But first try to guess what the values will be.
<code>
public class A
{
public int mVar = 10;
......
}
public class B extends A
{
public int mVar = 20;
......
}
...........
...........
</code>
Why does this program output AAA.
I checked the instance of a3 using instanceof and it shows 'C', so why isn't the m1() of class C getting called !!! It's driving me nuts.
---------------------
public class Inheritance
{
public class A
{
public void m1(A a)
{
System.out.println("A");
}
}

public class B extends A
{
public void m1(B b)
{
System.out.println("B");
}
}

public class C extends B
{
public void m1(C c)
{
System.out.println("C");
}
}

public static final void main (String args[])
{
Inheritance i = new Inheritance();
Inheritance.A a1 = i.new A();
Inheritance.A a2 = i.new B();
Inheritance.A a3 = i.new C();
Inheritance.C c1 = i.new C();
a1.m1(c1);
a2.m1(c1);
a3.m1(c1);
/*
System.out.println("a1: " + a1);
System.out.println("a2: " + a2);
System.out.println("a3: " + a3);
c1.m1(a1);
c1.m1(a2);
c1.m1(a3);
*/
}
}
---------------------