rey leon

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

Recent posts by rey leon

Don't buy the Head First Java, that's a really bad book.

Originally posted by nikunj thakur:
their are 2 books of K&B 1-head 1st java and 2- sun certified java programmer

which one i should use 2 study for SCJP 1.5

Chandra:

I've spent some time on this code and this is what I think is happening:
The statement EPractice$1$5 e=new SubClass(); returns an object of type SubClass but it is being assigned to a EPractice$1$5 object, so the new object is treated as EPractice$1$5 object. So when you call the getObject() method it is the one defined in the EPractice$1$5 class that you are calling, not the one in the SubClass.
At the begining I tought too that the value 5 should be printed, but getObject() in SubClass does not override the one in EPractice$1$5 because e is of type EPractice$1$5.
I did this test: I added a new method in SubClass and called it like from e, but it does not compile, which confirms that e being treated as of type EPractice$1$5.



I hope that helps.


Originally posted by Chandra Kota:
Hello All,

Please find the below code



My question is e.getObject() method would return object of class B . Then accessing x on object b should display 6, but why is it displaying 5. Can any one explain the fundamental rule here.

Could somebody help me understand the logic behind implementing 2 interfaces that have identical methods?

yeah, i had noticed that too (String [] a = new String [1]; compiles!).

Originally posted by Chandra Kota:
Even I'm confused with this. When we declare and Initialize the array, there is no problem. But when we separate declaration and initialization, we are having the problem. Can anyone explain whats wrong with that.

hello,

i was testing something and can't see what i'm doing wrong with the code below. when i compile it, i get the msg that an identifier is expected in the line String [] a;. thxs.
Radha:

Add "static" to the array declaration to access it from the main method, and instantiate the array.




Originally posted by Radha Kamesh:
Sorry friends, this might turn out to be a really stupid doubt, but
i'm confused..

I dont get why this piece of code throws a NullPointerException at line 5



Thanks

Dilla,

For right-shifting you would shift the bits beginning from the right side (right-most). ex. 1111 1111 1110 1000, begin by shifting the 0's.

Originally posted by Jay Dilla:
I'm confused about WHERE the shifting begins. For instance let's say we have a problem like . That bit representation would be . My question is where do I begin shifting the bits? At the 1 or at the 0 following the 1? Is it or ?

Dilla,

"++" has higher precedence than "=", so j will get the new value after i has been incremented. But because of postfix operation in i, j will get the value in i before being incremented.

hope this helps.

Originally posted by Jay Dilla:
i'm taking the exam friday and still can't grasp this basic idea.
let's say we have a code snippet like:


at line 2 j will be 10, but i will be 11?
so you can assign a postoperand and get the preoperand value?
but the variable that uses the postoperand will still have to wait to get the real value?
when does the post operand variable get the new value? does it have to be called again or something?

Anyone knows the answer to the above question? Any idea would be greatly appreciated. thanks.
by the way, the anser is ompile time error.

Originally posted by V Gala:
interface Bicycle{
public void Bicycle();
}
public class Jchq {
public static void main(String argv[]){
Jchq j = new Jchq();
Bicycle b = (Bicycle) j;
}
}

what should be the answer the compile time error or runtime error

V Gala:

The problem in your code is that you are trying to instantiate Jchq within its own definition. I don't think that you can do that. I had a similar problem before.

If you comment out the instantiation and casting statements it does compile:

interface Bicycle{
public void Bicycle();
}

public class Jchq {
public static void main(String argv[]){
//Jchq j = new Jchq();
//Bicycle b = (Bicycle) j;
}
}

Originally posted by V Gala:
interface Bicycle{
public void Bicycle();
}
public class Jchq {
public static void main(String argv[]){
Jchq j = new Jchq();
Bicycle b = (Bicycle) j;
}
}

what should be the answer the compile time error or runtime error

hello all!

Does any body know why negating 3 gives -4? If I negate 5 and print the new value, it prints 6.

---here's the code ----

public class Test
{
public static void main (String [] args)
{
byte n = 3;
n = (byte) ~n;

System.out.println(n);

}
}

---- end code ---
thanks.

Originally posted by Burkhard Hassel:
Howdy Leon,

welcome to the Ranch!




No, there are no questions about swing and awt.
Perhaps our FAQ page could be helpfull for you:
http://faq.javaranch.com/view?ScjpFaq



Yours,
Bu.




Thanks a lot!