Simon Edwards wrote:In the following code, does method row() in interface Derived overrides method row() in interface Base, or hides it?
Thanks.
Ashish Dutt wrote:Dear friends,
I have a slight confusion here.
My question is, "In order to take the OCJP7 certification exam, is it imperative to take the OCJA 7 exam first?"
Please do clarify the doubt.
Joe Allen wrote:Thanks for replying.
If T is Integer, wouldn't the following code blow up?
class Pie<Integer> {
public static void main(String... args) {
Pie<Fruit> p=new Pie<Fruit>(); //Pie is Integer, not Fruit???
}
}
Zhenyi, thanks for the generic link. In fact, I postponded my OCPJP6 exam from Friday to Monday, just to study generics in that link over the weekend. But after the exam, I am still confused about it. Luckily I did get the generic question in the exam correct.
Jesper de Jong wrote:
Zhenyi Luo wrote:The thread class's start method is overloaded, and can not start the run() method.
It is not overloaded, but overridden.
Overloading = multiple methods with the same name, but different parameters
Overriding = method in a subclass which has the same name and the same parameters as a method in a superclass
If you override a method, then the method in the superclass that you are overriding is not called automatically. If you want the superclass version to be executed as well, you'll need to call it explicitly with super:
vishal mishra wrote:
Dan Drillich wrote:The + is counted into the 5.
Please try -
which prints +000009758.
Regards,
Dan
Thanks for replying..
I understand that but i want to know why it didn't print 09758 ? Why +9758?Why it has given preference to '+' not to ' 0' ?
And when i tried this statement
then also it prints the same +9758
I am not getting....so please explain....
Thanks
Joe Allen wrote:class MyThread extends Thread {
public void run() { System.out.println("MyThread: run()"); }
public void start() { System.out.println("MyThread: start()"); }
}
public class ThreadTest {
public static void main(String args[]) {
MyThread myThread = new MyThread();
myThread.start();
}
}
It prints "MyThread: start()".
My question is why run() in this class is not called to print out "MyThread: run()"?
Would anyone care to explain?
Joe Allen wrote:From K&B's mock exam:
class Food {}
class Fruit extends Food {}
class Apple extends Fruit {}
//insert code here
public static void main(String... args) {
Pie<Fruit> p=new Pie<Fruit>();
}
}
Correct answers:
A:class Pie<T extends Food> {
B:class Pie<T extends Fruit> {
F:class Pie<T> {
Would someone please explain why answer F?
Thanks.
Joe Allen wrote:import java.io.*;
abstract interface Veloz { void metodo(String x); }
public class A {
private abstract interface Veloz{ Number metodo(int x); }
abstract static class B{
private abstract static interface Veloz{void metodo(long x) throws Exception;}
public void metodo(){
class Opa implements Veloz{
public void metodo(long x) throws IOException { }
}
}
}
public void test(){
class Opa2 implements Veloz{
public Integer metodo(int x) throws RuntimeException {
return (Integer)(int) .5f;
}
}
}
}
===========================
private abstract static interface?
abstract static class?
I don't understand. Hopefully I don't get all confused and messed up before taking the exam.
vishal mishra wrote:Namaste Friends !!
Is it good for me to complete this exam in 3 hours or I must try to Complete this exam in 2 hours 30 minutes which is the time limit for real exam ?
Please guide me....
Thanks
Adam Crawford wrote:Hi all,
I've got the SCJP 6 exam coming up in just over a week and was going over some CertPal questions for practice. This evening I came across this one:
With one of the following answers:
1) Hi
2) No Ouput
3) Compile error
4) Runtime error
5) None of the above
I chose 4 (runtime error) as the class doesn't implement Comparable, but it was marked wrong and the correct answer given was 1 (Hi) because:
"The code to compare the elements in the set will kick in only when the next element is added. Adding more than one element to this set will result in a runtime exception".
Yet, when I try this out, I get a runtime exception until I add an "implements Comparable" and a compareTo method - at which point I get the answer "Hi".
Am I missing something?
Thanks.
Adam.
Mahtab Alam wrote:public class Hose<E extends Hose>
{
E innerE;
public E get(E e,Hose<E>e2)
{
return e.getE(); //compiler says found Hose
}
E getE()
{
return innerE;
}
}
I know for compiler get() methods return type can only be E nothing else
Please explain clearly ,
Mahtab Alam wrote:
public class MyStuff {
MyStuff(String n) { name = n; }
String name;
public static void main(String[] args) {
MyStuff m1 = new MyStuff("guitar");
MyStuff m2 = new MyStuff("tv");
System.out.println(m2.equals(m1));
}
public boolean equals(Object o) {
MyStuff m = (MyStuff) o;
if(m.name != null)
return true;
return false;
}
}
Answer is :prints false and MyStuff does not fulfills Object.equals() contract
so it means Object.hashCode() contract is included in Object.equals() contract
Mahtab Alam wrote:Now compiler complaint a Local variable x and a block variable x
class R
{
public static void main(String args[])
{
show(10);
}
static void show(int x)
{
for(int x=1;x<2;x++)
System.out.println(x);
}
}
compiler say x is already defined in show(int)
When scope conflict occurs then there is problem.
So why there is no scope conflict in the first code
Mahtab Alam wrote:class Cast
{
public static void main(String args[])
{
Short s=new Short((short)10);
show(s);
}
static void show(int i)
{
System.out.println("Great");
}
}
This works so it means that Short is first unboxed to short which is then widened to int