Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice Questions)



Question : You are asked to develop a program for a shopping application, and you are given the following information:
The application must contain the classes Toy, EduToy, and consToy. The Toy class is the superclass of the other two classes.

The
int caicuiatePrice (Toy t)
method calculates the price of a toy.

The void printToy (Toy t)
method prints the details of a toy.

Which definition of the Toy class adds a valid layer of abstraction to the class hierarchy?
 : You are asked to develop a program for a shopping application, and you are given the following information:
1.
public abstract class Toy{
public abstreact int caicuiatePrice (Toy t) ;
void printToy (Toy t) {/*code goes here*/}
}

2.
public abstract class Toy{
public int caicuiatePrice (Toy t) ;
void printToy (Toy t);
}
3. Access Mostly Uused Products by 50000+ Subscribers
public abstract class Toy{
public int caicuiatePrice (Toy t) ;
public final void printToy (Toy t) {/*code goes here*/}
}

4.
public abstract class Toy{
public abstract int caicuiatePrice(Toy t){/*Code goes here*/} ;
void printToy (Toy t){/*Code goes here*/};
}




Correct Answer : Get Lastest Questions and Answer : Exp




Question : You have been given following code

public static void main(String[] args) {
int[] intArr = {15,30,45,60,75};
intArr[2] = intArr[4];
intArr[4] = 90;

for (int i = 0; i < intArr.length; i++) {
System.out.print(intArr[i] + ", ");
}
}

After executing this code, what would be printed

 : You have been given following code
1. 15, 60, 45, 90, 75,
2. 15, 90, 45, 90, 75,
3. Access Mostly Uused Products by 50000+ Subscribers
4. 15, 30, 90, 60, 90,
5. 15, 4, 45, 60, 90,


Correct Answer : Get Lastest Questions and Answer :

Explanation:





Question : You have been given following arrays

int[] intArr = {8,16,32,64,128};

which two code fragements , independently , print each element in this array?

A. for(int i : intArr){
System.out.print(intArr[i] + ", ");
}

B. for(int i : intArr){
System.out.print(i + ", ");
}

C. for(int i=0 : intArr){
System.out.print(intArr[i] + ", ");
i++;
}

D. for(int i=0 ; i System.out.print(i + " ");
}

E. for(int i=0 ; i System.out.print(intArr[i] + " ");
}

F. for(int i; i System.out.print(intArr[i] + " ");
}

 : You have been given following arrays
1. A,B
2. C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. E,F
5. B,E

Correct Answer : Get Lastest Questions and Answer :





Related Questions


Question : You have been given below code

public class FieldInit {
char c;
boolean b;
float f;

void printAll() {
System.out.println("c = " + c);
System.out.println("c = " + b);
System.out.println("c = " + f);
}

public static void main(String[] args) {
FieldInit f = new FieldInit();
f.printAll();
}
}

What would be result ?

 : You have been given below code
1. c = null
b = false
f = 0.0F
2. c = 0
b = false
f = 0.0f
3. Access Mostly Uused Products by 50000+ Subscribers
b = true
f = 0.0
4. c =
b = false
f = 0.0





Question : You have been given following code

int a = 0;
a++;
System.out.println(a++);
System.out.println(a);

What would be the result ?

 : You have been given following code
1. 1

2. 0

3. Access Mostly Uused Products by 50000+ Subscribers

4. 2





Question : You have been given following code

public class Test {
public static void main(String[] args) {
int arr[] = new int[4];
arr[0] = 1;
arr[1] = 2;
arr[2] = 4;
arr[3] = 5;
int sum = 0;
try {
for (int pos = 0; pos <= 4; pos++) {
sum = sum + arr[pos];
}
} catch (Exception e) {
System.out.println("Invalid index");
}
System.out.println(sum);
}
}

What would be printed ?
 : You have been given following code
1. 12
2. Invalid Index 12
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails





Question : :
int [] array = {1,2,3,4,5};
for (int i: array) {
if ( i < 2) {
keyword1 ;
}
System.out.println(i); if ( i == 3) {
keyword2 ;
}}

What should keyword1 and keyword2 be respectively, in oreder to produce output 2345?
 : :
1. continue, break
2. break, break
3. Access Mostly Uused Products by 50000+ Subscribers
4. continue, continue





Question :

package p1;
public interface DoInterface {
void method1(int n1); // line n1
}

package p3;
import p1.DoInterface;
public class DoClass implements DoInterface {
public DoClass(int p1) { }
public void method1(int p1) { } // line n2
private void method2(int p1) { } // line n3
}

public class Test {
public static void main(String[] args) {
DoInterface doi= new DoClass(100); // line n4
doi.method1(100);
doi.method2(100);
}
}
Which change will enable the code to compile?

 :
1. Adding the public modifier to the declaration of method1 at line n1
2. Removing the public modifier from the definition of method1 at line n2
3. Access Mostly Uused Products by 50000+ Subscribers
4. Changing the line n4 DoClass doi = new DoClass ( );




Question : Consider

Integer number = Integer.valueOff 808.1");

Which is true about the above statement?

 : Consider
1. The value of the variable number will be 808.1
2. The value of the variable number will be 808
3. Access Mostly Uused Products by 50000+ Subscribers
4. A NumberFormatException will be throw.
5. It will not compile