Oracle Java Certified Programmer - 1Z0-501 Exam Practice Test
Given:
1 . class BaseClass{
2 . private float x= 1.0f;
3 . protected void setVar (float f) {x = f;}
4 . }
5 . class SubClass exyends BaseClass {
6 . private float x = 2.0f;
7 . //insert code here
8 .}
Which two are valid examples of method overriding? (Choose Two)
1 . class BaseClass{
2 . private float x= 1.0f;
3 . protected void setVar (float f) {x = f;}
4 . }
5 . class SubClass exyends BaseClass {
6 . private float x = 2.0f;
7 . //insert code here
8 .}
Which two are valid examples of method overriding? (Choose Two)
Correct Answer: C,D
Exhibit:
1 . class A {
2 . public String toString (){
3 . return "4";
4 .}
5 .}
6 . class B extends A {
7 .8.public String toString (){
8 . return super.toString()+ "3";
9 .}
1 0. }
1 1. public class Test {
1 2. public static void main(String[]args){
1 3.System.out.printIn(new B());
1 4.}
15.}
What is the result?
1 . class A {
2 . public String toString (){
3 . return "4";
4 .}
5 .}
6 . class B extends A {
7 .8.public String toString (){
8 . return super.toString()+ "3";
9 .}
1 0. }
1 1. public class Test {
1 2. public static void main(String[]args){
1 3.System.out.printIn(new B());
1 4.}
15.}
What is the result?
Correct Answer: C
Given:
1. public class Foo {
2 . public static void main (String [] args){
3 .StringBuffer a = new StringBuffer ("A");
4 .StringBuffer b = new StringBuffer ("B");
5 .operate (a,b);
6 .system.out.printIn{a + "," +b};
7 . )
8 . static void operate (StringBuffer x, StringBuffer y){
9 .x.append {y};
1 0.y = x;
1 1.)
1 2.}
What is the result?
1. public class Foo {
2 . public static void main (String [] args){
3 .StringBuffer a = new StringBuffer ("A");
4 .StringBuffer b = new StringBuffer ("B");
5 .operate (a,b);
6 .system.out.printIn{a + "," +b};
7 . )
8 . static void operate (StringBuffer x, StringBuffer y){
9 .x.append {y};
1 0.y = x;
1 1.)
1 2.}
What is the result?
Correct Answer: E
Given the ActionEvent, which method allows you to identify the affected component?
Correct Answer: B
Given:
1 . public class Foo {
2 . private int val;
3 . public foo(int v) (val = v;)}
4 . public static void main (String [] args){
5 . Foo a = new Foo (10);
6 . Foo b = new Foo (10);
7 . Foo c = a;
8 . int d = 10;
9 . double e = 10.0;
1 0. }
1 1. }
Which three logical expression evaluate to true? (Choose Three)
1 . public class Foo {
2 . private int val;
3 . public foo(int v) (val = v;)}
4 . public static void main (String [] args){
5 . Foo a = new Foo (10);
6 . Foo b = new Foo (10);
7 . Foo c = a;
8 . int d = 10;
9 . double e = 10.0;
1 0. }
1 1. }
Which three logical expression evaluate to true? (Choose Three)
Correct Answer: A,D,F
Given:
1. //point X
2 . public class foo (
3 . public static void main (String[]args) throws Exception {
4 . java.io.printWriter out = new java.io.PrintWriter (
5 . new java.io.outputStreamWriter (System.out), true;
6 . out.printIn("Hello");
7 . }
8 . }
Which statement at PointX on line 1 allows this code to compile and run?
1. //point X
2 . public class foo (
3 . public static void main (String[]args) throws Exception {
4 . java.io.printWriter out = new java.io.PrintWriter (
5 . new java.io.outputStreamWriter (System.out), true;
6 . out.printIn("Hello");
7 . }
8 . }
Which statement at PointX on line 1 allows this code to compile and run?
Correct Answer: C