Win a copy of Rust Web Development this week in the Other Languages forum!

Nikhil Pujari

Greenhorn
+ Follow
since Oct 31, 2011
Nikhil likes ...
Firefox Browser C++ Windows
I am a friendly, honest and reliable guy.
India
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Nikhil Pujari

This question is about overriding and instance variables. Now I know instance variables cannot be overridden, but I can't get this. I found this in the Rules Roundup game.



I thought the System.out.println(name) is replaced within the Test class as System.out.println(this.name). But that doesn't seem to be the case. Why is this?
You were right. I had a CharSequence.class file in the package. I should have tried compiling it in NetBeans before asking. Thanks anyway.
This program is from the K&B SCJP book (exam version 1.5). I understand the program but it doesn't compile. The complete program and error are listed below:



error:


Thanks.
@ravi: Explicit casting works, but I wonder why I need it. It seems redundant.

Edit: I think I get it. Please tell me if I am wrong. if T is "Number", List<? extends T> can return List<Short> or List<Float>. These cannot be caught in a List<Integer>, hence the cast.

You need a cast for List<Number> because, the only thing a List<Number> variable can point to, is a List<Number>. It cannot point to a List<Integer>, even though Integer is-a Number.

Is this right?
This question is regarding generics.

In the below program, the return type (alist2 and alist3) meet the conditions set in the return portion of the method signature (which is List<? extends T>). Yet, I get an error. Thanks in advance. The program follows:

This is the question I am talking about:



This is the explanation offered in the answers section:

"The first call to wait() blocks forever. It's waiting for a notify(), but the notify() is never called because it's blocked on the wait(). In order for a notify() to be useful, it must be sent from a separate thread so that it can be called while the first thread is still waiting at the wait() statement."

Why and how do the two methods block on each other?

AFAIK, this is how it works: upon encountering the wait() method, the currently running thread releases its lock, which is reacquired. Then we encounter the notify() method (why is it waiting for the wait() method)? This is confusing...

Thanks

i got it. I feel like an idiot. Sorry guys.
I came across this question in the SCJP CD. It appears to have a syntax error -- the line that has "private A(String e){...}". I think this is an invalid constructor because it does not have the "()" after "A", but it seems to work fine. Why is that?

Here's a screenshot.



Thanks a ton. The thought that println may not be an atomic operation did cross my mind, but I wasn't sure. Thanks again.
I am new to threads, and I must say I have never spent more time understanding any other topic for the SCJP than this. Anyway, I wrote this simple threads program and I can't understand how the result was arrived at. Program and result are shown below.

Program:



result:



My question is regarding lines 7 and 9.There seems to be a jump in the value of "i" from 3 to 5, without first going thru 4, which shows up later. How can this be possible?
Hello all,

Why does the regex: abc[xyz]*def match the string abcxyzdef when the regex abc[xyz]?def fails to match the same string?

The character class [xyz] means match any one of x or y or z. Then, why does [xyz]* match all three?
10 years ago

Winston Gutkowski wrote:
It's maybe worth remembering that Class B doesn't inherit a copy of a1, it inherits a1 itself; because a class B is a class A.
However, a1 still belongs to class A, because that's where it is defined; and that is why class D can't access it.



Does that mean a1 is shared by objects of class A and class B? I thought an object of class B had a separate a1 than that of class A, and if you modified a1 in an object of class B, then the other one would not be affected.
10 years ago