I took Marcus Mock #2 last week and got 79%, and I was thinking to do better slowly. But today I took Marcus Mock#3 and completely lost my confidence. I am listing some of the questions, where I have doubts:
First of all, in one of the questions, there wasn't any match with the answer listed. So the description says, if you see this kind of problem in the exam, leave the question blank. Is it true?
Questions:
Which of the following statements are true?
1) The instanceof operator can be used to determine if a reference is an instance of a class, but not an interface.
2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class
3) The instanceof operator will only determine if a reference is an instance of a class immediately above in the hierarchy but no further up the inheritance chain
4) The instanceof operator can be used to determine if one reference is of the same class as another reference thus
Answer given is 2) I don't agree. Any thoughts?
Which of the following statements are true?
1) An interface can only contain method and not variables
2)
Java does not allow the creation of a reference to an interface with the new keyword.
3) A class may extend only one other class and implement only one interface
4) Interfaces are the Java approach to addressing its single inheritance model, but require implementing classes to create the functionality of the Interfaces.
My answer was 2) and 4). But the given answer is 4)
Which of the following statements are true?
1) All of the variables in an interface are implicitly static
2) All of the variables in an interface are implicitly final
3) All of the methods in an interface are implicitly abstract
4) A method in an interface can access class level variables
Given answer is 1),2),3). All the interface variables are implicitly final and static? Also, a method in a interface can't access class level variables in a class, which is implementing that interface?
Given a reference called t to to a class which extends
Thread, which of the following will cause it to give up cycles to allow another thread to execute.
1) t.yield();
2) yield()
3) yield(100) //Or some other suitable amount in milliseconds
4) yield(t);
Given answer is 2). I thought 1) should be correct answer (I know, yield() is static method of Thread class, but still you can access it using reference, right? Correct me if I am wrong. Also the description says yield() is static method of Object class.)
Given the following code
class Base {}
class Agg extends Base{
public
String getFields(){
String name = "Agg";
return name;
}
}
public class Avf{
public static void main(String argv[]){
Base a = new Agg();
}
}
What code placed after the comment //Here will result in calling the getFields method of Base resulting in the output of the string "Agg"?
1) System.out.println(a.getFields());
2) System.out.println(a.name);
3) System.out.println((Base) a.getFields());
4) System.out.println( ((Agg) a).getFields());
First of all, there is no //Here in above code. So I assume, it would be after Base a = new Agg(); and so my answer was 1). But given answer is 4).