Oracle 1z0-851 Exam Practice Questions (P. 2)
- Full Access (260 questions)
- Six months of Premium Access
- Access to one million comments
- Seamless ChatGPT Integration
- Ability to download PDF files
- Anki Flashcard files for revision
- No Captcha & No AdSense
- Advanced Exam Configuration
Question #6
Given:
public abstract class Shape {
private int x;
private int y;
public abstract void draw();
public void setAnchor(int x, int y) {
this.x = x;
this.y = y;
}
}
Which two classes use the Shape class correctly? (Choose two.)
public abstract class Shape {
private int x;
private int y;
public abstract void draw();
public void setAnchor(int x, int y) {
this.x = x;
this.y = y;
}
}
Which two classes use the Shape class correctly? (Choose two.)
- Apublic class Circle implements Shape { private int radius; }
- Bpublic abstract class Circle extends Shape { private int radius; }
- Cpublic class Circle extends Shape { private int radius; public void draw(); }
- Dpublic abstract class Circle implements Shape { private int radius; public void draw(); }
- Epublic class Circle extends Shape { private int radius; public void draw() {/* code here */} }
- Fpublic abstract class Circle implements Shape { private int radius; public void draw() {/* code here */}
Correct Answer:
BE
BE
send
light_mode
delete
Question #7
Given:
public class Barn {
public static void main(String[] args) {
new Barn().go("hi", 1);
new Barn().go("hi", "world", 2);
}
public void go(String... y, int x) {
System.out.print(y[y.length - 1] + " ");
}
}
What is the result?
public class Barn {
public static void main(String[] args) {
new Barn().go("hi", 1);
new Barn().go("hi", "world", 2);
}
public void go(String... y, int x) {
System.out.print(y[y.length - 1] + " ");
}
}
What is the result?
- Ahi hi
- Bhi world
- Cworld world
- DCompilation fails.
- EAn exception is thrown at runtime.
Correct Answer:
D
The method go(String[], int) in the type Barn is not applicable for the arguments (String, int)
The variable argument type String of the method go must be the last parameter
D
The method go(String[], int) in the type Barn is not applicable for the arguments (String, int)
The variable argument type String of the method go must be the last parameter
send
light_mode
delete
Question #8
Given:
class Nav{
public enum Direction { NORTH, SOUTH, EAST, WEST }
}
public class Sprite{
// insert code here
}
Which code, inserted at line 14, allows the Sprite class to compile?
class Nav{
public enum Direction { NORTH, SOUTH, EAST, WEST }
}
public class Sprite{
// insert code here
}
Which code, inserted at line 14, allows the Sprite class to compile?
- ADirection d = NORTH;
- BNav.Direction d = NORTH;
- CDirection d = Direction.NORTH;
- DNav.Direction d = Nav.Direction.NORTH;
Correct Answer:
D
D
send
light_mode
delete
Question #9
Which statement is true about the classes and interfaces in the exhibit?
01. public interface A {
02. public void doSomething(String thing);
03. }
01. public class AImpl implements A {
02. public void doSomething(String msg) {}
03. }
01. public class B {
02. public A doit(){
03. //more code here
04. }
05. public String execute(){
06 //more code here
07 }
08. }
01. public class C extends B {
02. public AImpl doit(){
03. //more code here
04. }
05.
06. public Object execute() {
07. //more code here
08. }
09. }
01. public interface A {
02. public void doSomething(String thing);
03. }
01. public class AImpl implements A {
02. public void doSomething(String msg) {}
03. }
01. public class B {
02. public A doit(){
03. //more code here
04. }
05. public String execute(){
06 //more code here
07 }
08. }
01. public class C extends B {
02. public AImpl doit(){
03. //more code here
04. }
05.
06. public Object execute() {
07. //more code here
08. }
09. }
- ACompilation will succeed for all classes and interfaces.
- BCompilation of class C will fail because of an error in line 2.
- CCompilation of class C will fail because of an error in line 6.
- DCompilation of class AImpl will fail because of an error in line 2.
Correct Answer:
C
The return type is incompatible with B.execute()
C
The return type is incompatible with B.execute()
send
light_mode
delete
Question #10
What is the result?
11. public class Person {
12. String name = "No name";
13. public Person(String nm) { name = nm; }
14. }
15.
16. public class Employee extends Person {
17. String empID = "0000";
18. public Employee(String id) { empID = id; }
19. }
20.
21. public class EmployeeTest {
22. public static void main(String[] args){
23. Employee e = new Employee("4321");
24. System.out.println(e.empID);
25. }
26. }
11. public class Person {
12. String name = "No name";
13. public Person(String nm) { name = nm; }
14. }
15.
16. public class Employee extends Person {
17. String empID = "0000";
18. public Employee(String id) { empID = id; }
19. }
20.
21. public class EmployeeTest {
22. public static void main(String[] args){
23. Employee e = new Employee("4321");
24. System.out.println(e.empID);
25. }
26. }
- A4321
- B0000
- CAn exception is thrown at runtime.
- DCompilation fails because of an error in line 18.
Correct Answer:
D
Implicit super constructor Person() is undefined. Must explicitly invoke another constructor
D
Implicit super constructor Person() is undefined. Must explicitly invoke another constructor
send
light_mode
delete
All Pages