Oracle 1z0-851 Exam Practice Questions (P. 5)
- 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 #21
Given:
05. class Building { }
06. public class Barn extends Building {
07. public static void main(String[] args) {
08. Building build1 = new Building();
09. Barn barn1 = new Barn();
10. Barn barn2 = (Barn) build1;
11. Object obj1 = (Object) build1;
12. String str1 = (String) build1;
13. Building build2 = (Building) barn1;
14. }
15. }
Which is true?
05. class Building { }
06. public class Barn extends Building {
07. public static void main(String[] args) {
08. Building build1 = new Building();
09. Barn barn1 = new Barn();
10. Barn barn2 = (Barn) build1;
11. Object obj1 = (Object) build1;
12. String str1 = (String) build1;
13. Building build2 = (Building) barn1;
14. }
15. }
Which is true?
- AIf line 10 is removed, the compilation succeeds.
- BIf line 11 is removed, the compilation succeeds.
- CIf line 12 is removed, the compilation succeeds.
- DIf line 13 is removed, the compilation succeeds.
- EMore than one line must be removed for compilation to succeed.
Correct Answer:
C
Cannot cast from Building to String
C
Cannot cast from Building to String
send
light_mode
delete
Question #22
A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the
API without losing any functionality. If they implement the new design, which two OO principles will they be promoting?
API without losing any functionality. If they implement the new design, which two OO principles will they be promoting?
- ALooser coupling
- BTighter coupling
- CLower cohesion
- DHigher cohesion
- EWeaker encapsulation
- FStronger encapsulation
Correct Answer:
A
A
send
light_mode
delete
Question #23
Given:
21. class Money {
22. private String country = "Canada";
23. public String getC() { return country; }
24. }
25. class Yen extends Money {
26. public String getC() { return super.country; }
27. }
28. public class Euro extends Money {
29. public String getC(int x) { return super.getC(); }
30. public static void main(String[] args) {
31. System.out.print(new Yen().getC() + " " + new Euro().getC());
32. }
33. }
What is the result?
21. class Money {
22. private String country = "Canada";
23. public String getC() { return country; }
24. }
25. class Yen extends Money {
26. public String getC() { return super.country; }
27. }
28. public class Euro extends Money {
29. public String getC(int x) { return super.getC(); }
30. public static void main(String[] args) {
31. System.out.print(new Yen().getC() + " " + new Euro().getC());
32. }
33. }
What is the result?
- ACanada
- Bnull Canada
- CCanada null
- DCanada Canada
- ECompilation fails due to an error on line 26.
- FCompilation fails due to an error on line 29.
Correct Answer:
E
The field Money.country is not visible
E
The field Money.country is not visible
send
light_mode
delete
Question #24
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:
13. import java.io.*;
14. class Food implements Serializable {int good = 3;}
15. class Fruit extends Food {int juice = 5;}
16. public class Banana extends Fruit {
17. int yellow = 4;
18. public static void main(String [] args) {
19. Banana b = new Banana(); Banana b2 = new Banana();
20. b.serializeBanana(b); // assume correct serialization
21. b2 = b.deserializeBanana(); // assume correct
22. System.out.println("restore "+b2.yellow+ b2.juice+b2.good);
24. }
25. // more Banana methods go here
50. }
What is the result?
13. import java.io.*;
14. class Food implements Serializable {int good = 3;}
15. class Fruit extends Food {int juice = 5;}
16. public class Banana extends Fruit {
17. int yellow = 4;
18. public static void main(String [] args) {
19. Banana b = new Banana(); Banana b2 = new Banana();
20. b.serializeBanana(b); // assume correct serialization
21. b2 = b.deserializeBanana(); // assume correct
22. System.out.println("restore "+b2.yellow+ b2.juice+b2.good);
24. }
25. // more Banana methods go here
50. }
What is the result?
- Arestore 400
- Brestore 403
- Crestore 453
- DCompilation fails.
- EAn exception is thrown at runtime.
Correct Answer:
C
C
send
light_mode
delete
Question #25
Given a valid DateFormat object named df, and
16. Date d = new Date(0L);
17. String ds = "December 15, 2004";
18. //insert code here
What updates d's value with the date represented by ds?
16. Date d = new Date(0L);
17. String ds = "December 15, 2004";
18. //insert code here
What updates d's value with the date represented by ds?
- Ad = df.parse(ds);
- Bd = df.getDate(ds);
- Ctry { d = df.parse(ds); } catch(ParseException e) { };
- Dtry { d = df.getDate(ds); } catch(ParseException e) { };
Correct Answer:
C
C
send
light_mode
delete
All Pages