Jong Limb

Greenhorn
+ Follow
since May 08, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jong Limb

Here is the exact quote from The Java Programming Language:

In contrast to the non-wildcard versions, parameterized types that include a bounded wildcard are
related in the way you might have expected. For example, List<?extends Integer> is a subtype
of List<?extends Number>, which is itself a subtype of List<? >. Similarly, List<?super
Number> is a subtype of List<?super Integer>.



I understand List<? extends Integer> being a subtype of List<? extends Number>, but I don't understand why List<? super Number> is a subtype of List<? super Integer>. Can someone explain this to me?
14 years ago
String is derived from Object and is therefore, more specific.
The problem in scenario 1 isn't one of visibility, but of syntax. It looks to the compiler that you are declaring a member variable of type value1 and you want to assign a value of 1 to it, but you didn't specify an identifier.

If you provide a type for value1, as in

then you've declared a valid member variable, but hidden the value1 from interface A.

As you've already seen, you can reference value1 in the class, but you can't modify the value. So, you can have

Originally posted by Angela lewis:
K&B page 82
Just remember that default members are visible only to the subclasses that are in the same package as the superclass.

Does that mean class that are in the same package but not subclasses
cannot access default memebers.
I tried the following code and it works




Am i interpreting it incorrectly?




There are two questions involved here. One is the package location of a subclass in relation to its superclass. For this point, default members are not accessible when the subclass is in a different package than the superclass. Protected members, in contrast, *are* accessible to subclasses regardless which package the subclass is in.

The second question is the accessibility of default members for classes in the same package that aren't subclasses. Any class in the same package can access default members. That is why your example works.
k += ++k resolves to k = k + ++k. Taking the right hand side and evaluating left to right, you get k = 0 + ++(0). This resolves to k = 0 + 1; therefore k = 1.

Originally posted by Sridhar Srinivasan:
Hi!
When I compile the following code I get the value as 1
public static void main(String[ ] args)
{

int k=0;
k += ++k;
System.out.println(k);
}
As per my understanding, bec's of operator precedence k becpomes 1 first and now k holds the value of 1 and then when we say k+=1 which is k=k+1(1+1) is 2.Why is it giving 1?Can anybody please explain.Thanks

Yes, assertions can be used to validate arguments to non-public methods. Choice 'b' says that you should not do this; therefore, it is *not* true. Since you only select the statements that *are* true, choice 'b' is not a right answer.
It's not a matter of bits; it's a matter of precision. Longs can only hold integral values. Floats can hold fractional values. If your float variable contained the value 12.34, what happens to the 0.34? It gets truncated. The compiler will flag this for you as a loss of precision.
The while loop checks i++ which returns the value of i and then increments it. So after the i == (args.length - 1) test returns true, i will equal args.length. Since you can only reference args[0] - args[args.length - 1], you will get an array out of bounds exception.
If you have a private constructor, you can't use something like:

So in order to create a new instance, the class must provide a method that will create an instance for you or a variable to a pre-created instance. For example, the following gives you a method that creates an instance:

The following provides a variable to a pre-created instance.

Note that this is not a tightly encapsulated class and is only for illustrative purposes.
[ May 10, 2004: Message edited by: Jong Limb ]
[ May 10, 2004: Message edited by: Jong Limb ]
If you have, for example,

the (++i) and (i++) would not get evaluated first. The "j = ..." expression is evaluated left to right.
So, in this case, the i++ returns 0, but sets i to 1. The (++i) returns and sets i to 2. The (i++) returns 2 and sets i to 3. This is another case where code in () does not get evaluated first.
[ May 08, 2004: Message edited by: Jong Limb ]
I just passed the Java programmer certification this morning.
Many thanks to Kathy and Bert for their book, and Dan Chisholm for his tests.
My study pattern was to read Kathy and Bert's book, take Dan Chisholm's mock tests, feel incredibly stupid about what I didn't know, re-read Kathy and Bert's book and pick up on a bunch of things that I missed the first time around, and continue to take Dan's mock tests.
The difficulty of the actual exam is slightly higher than the type of questions in the book, but much lower than Dan's mock tests.
On to the BCD certification.
20 years ago