Alina Petra

Greenhorn
+ Follow
since Oct 17, 2006
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 Alina Petra

First, you don't have a no - arg constructor in the superclass (you need one because the subclass constructor will call super() implicitly).

Second, you call a non - static method from a static context.
I passed SCJP 5.0 yesterday with 87%. I would have liked to score at least 90%, but i had some lack of concentration. I haven't managed to complete 3 of the questions, eventhough on the mock exams i'd always finished to answer to all the questions in half of the time.

Thank you Kathy and Bert for your book. I really enjoyed reading it, it is very well written and enough to pass this exam.

Thank you ranchers for your inqueries and replies.

Some data about my preparation: i have more than 3 years java programming experience, i've read K&B book twice and i did the two master exams and the whizlabs mock exams.

Good luck to all who need some

Alina
14 years ago
Which of the following lines can be compiled?

a)Basket<Apple>[] b = new Basket<Apple>[10];

b)Basket<?>[] b = new Basket<Apple>[10];

c)Basket<?>[] b = new Basket<?>[10];

d)public <T> T[] test() {return null;}

e)public <T> T[] test() {return new T[10];}

Can anyone give the right answer followed by explanation?
Abstract classes can not be instantiated, but they have constructors and their constructors are called when one instantiates the concrete subclasses.
If you have a collection declared as List<? super X> where X is a certain class, you are allowed to add to the collection only objects that pass IS-A X relationship.
MyInner() class is accessible, you are able to see it, but you can not instantiate it because the constructor has protected access. If the constructor had public access, you could instantiate it as well.
The MyInner() constructor is declared protected. Therefore you can not instantiate MyInner class from somewhere else other then the package outer.
I forgot to say that in the second case, an import MyOuter.MyInner is required.

Maybe it should be specified in the book that inner classes names can contains simply the name (without the outer class name) as long as the inner classes are imported as: import somePackage.MyOuter.MyInner;
Page 642:
"From outside the outer class instance code (including static method code within the outer class), the inner class name must now include the outer class's name:
MyOuter.MyInner"

This is not quite true. The inner class name can be MyOuter.MyInner, BUT it can be simply MyInner as well.
Your class PKS doesn't declare any constructor, therefore the default constructor will be provided by compiler. The default constructor has an implicit call to super(), therefore your superclass PK must have a constructor with no arguments for this code to compile.

Because you cannot call a static method with super.



This is false. You CAN call static methods using super. Actually that was all about within my question.
1. I think that reading Using Maps section (page 563) would help.

2. t1.equals(t2) returns false because the hashCode() is not overriden, therefore the output will be 3.
But if the hashCode() is overriden, then t1.equals(t2) will return true, therefore the output will be 2.
If you look at the overridden equals() method within the String class you see that it checks if the object given as parameter is an instance of String. If it's not, it retuns false. And since you compare your String object with a StringBuffer object you get false.
You imported all statics from mixed.xyz.Test class. Inner enum is static as well (by default) therefore it was also imported.
Sorry, i was wrong. The code does not compile because of the super within the static context. I focused on something else that's why the things got a bit mixed up

The answer is:
C is correct. Only instance methods can be overridden, and calls to super only apply to overridden methods.

In fact this answer got me confused. I haven't noticed that the call to super is done within a static context. That can not work, you are right.

But the explanation (

calls to super only apply to overridden methods

) is not correct, do you agree?