Lukas Sieradzki

Ranch Hand
+ Follow
since Jun 09, 2009
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 Lukas Sieradzki

Henry Wong wrote:

Lukas Sieradzki wrote:interface's methods are implicitly:
public abstract
interface's variables are implicitly:
public static final
You cannot change it.



Interesting points... but this topic is not about interfaces.

Henry


You are right but private is not public so I typed that modifiers for methods and variables in the interface cannot be changed. This is my explanation. The second explanation was also provided. private can't go with abstract because overriding won't be possible.
interface's methods are implicitly:
public abstract
interface's variables are implicitly:
public static final
You cannot change it.
I think it is not fair. Why are those bugs in the exam?
Yes, but what about the static reference?
So SCJP Exam has some bugs? It won't be fair
At the end x must be 33...

Your alternative answer is legal for Java, but the result is NOT 33 for x.
You can get a voucher if you are fe. a student

Ben Zaidi wrote:Hi,
In K&B book page 104, chapter, an example in exam watch is givenclass Animal {
public void eat() throws Exception {
// throws an Exception
}
}
class Dog2 extends Animal {
public void eat() { // no Exceptions }
public static void main(String [] args) {
Animal a = new Dog2();
Dog2 d = new Dog2();
d.eat(); // ok
a.eat(); // compiler error -
// unreported exception
}
}

I have a query, why the compiler is looking at the Dog verison of eat method. Though at compile time,
compiler sees the reference type rather then actual object type. Then why it is saying unhandled exception,
though it must see the animal version of the eat method, which is handling the exception




Though at compile time, compiler sees the reference type rather then actual object type. - YES, INDEED! You are absolutely right. Polymorphysm works during the runtime.

Then why it is saying unhandled exception,
though it must see the animal version of the eat method, which is handling the exception - NO. You don't handle this exception. You only report it - "throws" keyword. Handling an exception means:
1). try{}catch(){}
2). Or to pass the exception higher.

1).try{
a.eat();
}catch(Exception ex){ ex.printStackTrace();}

2).
public static void main(String [] args) throws Exception

That should work. Am I right?
Object B1 is on the heap. But reference to this object should be also ont the heap.
But on the other hand: in K&B:
- object and instance variables are on the heap,
- local variables and methods are on the stack.
So what about static variable? Is it like instace variable in this case? I have to ask someone with wider knowledge than me.

Please, help
You've created quite a good picture! MSPaint?

It's good. Left column (references) is on the stack and right column is on the heap.

Object B1 is NOT eligible for GC because you still have reference to it through the static variable. Static variable is ONE to THE CLASS not to the instance. Even if you delete (null) all of the references you will have the reference to B1 object. STATIC IS NOT CONNECTED WITH INSTANCE! Am I right?

I think I've cleared this out.

Akanksha Joy wrote:
The code is taken from the K&B book page 62 chapter1 (latest edition). There are many ways to declare an enum. The above is one the way i.e inside a class. But its not working. There's error in compiling. I think the enclosing class name is required...it's as if a nested class.......



In class Coffee just type CoffeeTest2.CoffeSize instead of CoffeeSize and everything will be allright.
If you want to reach inner class from outer class you should use the full path. The same if you want to run a class within console and that class is inside a package: then you type -> java package.MyMagicClass

All the best!

jeetendra Choudhary wrote:I have Doubt on behavior of !=, == and equals method in following example from K&B. please some one explain little bit more about that. sorry for such stupid question.


Thanks In Advance.



The output is:
Different Object
Meaningfuly Equal
Same object
Meaningfuly Equal

I am just a human compilator

If we perform == on Integer, Short and Byte wrapper objects whose boxing value is from interval (-128; 127), the operator returns true. Very important is that those values must be AUTOboxed. If we would create them using operator new, we were given false by ==. new always allocates new space in memory.

This question was answered a couple of times, so read the forum carefully, please

Hello Everyone!
What do you think about it? Are there any possibilities that JAva will vanish because of that or java will not be free?
Will be there any difficulties for Java programmers?
Thanks for replies!
14 years ago

Srikanth Nakka wrote:Polymorphism doesn't apply for static. this is not overriding but we can say Hiding


Or more accurately - redefining the static method