Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQuest

 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are 2 Q from JQuest
What should be at //A to output running
class RunThread implements runnable {
RunTest rt = new RunTest();
Thread t = new Thread(rt);
// A
}
public void run() {
System.out.println("running");
}
void go(){
start(1);}
void start(int i) {
}
a) t.start();
b)rt.start();
c)System.out.println("running");
d) start(1);
a,c are the given answers. Why is c? I feel only a
Here is my 2nd Q
2) class A {
public void method(int i, floatf){
//Some code
}
}
public class B extends A {
// Comment here
}
What should be // here
a) void method (inti,floatf)
b) public void method(inta,floatb)
c) public void method()
d) protected int method(floatb,int a)
Answers given are b,c,d. i feel only b,c
Can anybody explain?
Madhuri.
 
Lokesh Mahajan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Dear
In first example insted of RunTest it should be RunThread,
Problem is what is going to print "running",so if you give just simple System.out.println("running"); it is going to print "running", here it is not going to call run method,so only single "running"is the output.
so both the option given are correct.
About 2 question.
option d is also right because it is the case of overloading ,
option b & c are the case of overriding.
love
Lokesh
 
madhuri vl
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you. so changing the order of the parameters is Overloading.Ok
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic