Premium

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



Question : What is the proper way to defined a method that take two int values and returns their sum as an int value?

 : What is the proper way to defined a method that take two int values and returns their sum as an int value?
1. int sum(int first, int second) { first + second; }
2. int sum(int first, second) { return first + second; }
3. Access Mostly Uused Products by 50000+ Subscribers
4. int sum(int first, int second) { return first + second; }

5. void sum (int first, int second) { return first + second; }



Correct Answer : Get Lastest Questions and Answer :
Explanation:








Question : You have been given following code

public class MyClass {
public static void main(String[] args) {
String s = " Java Duke ";
int len = s.trim().length();
System.out.print(len);
}
}

What is the result?
 : You have been given following code
1. 8
2. 9
3. Access Mostly Uused Products by 50000+ Subscribers
4. 10
5. Compilation fails



Correct Answer : Get Lastest Questions and Answer :
Explanation: Java - String trim() Method
This method returns a copy of the string, with leading and trailing whitespace omitted.








Question : You have been given following code

public class SampleClass {
public static void main(String[] args) {
AnotherSampleClass asc = new AnotherSampleClass();
SampleClass sc = new SampleClass();
sc = asc;
System.out.println("sc: " + sc.getClass());
System.out.println("asc: " + asc.getClass());
}
}

class AnotherSampleClass extends SampleClass {
}

When you execute it, what will be printed ?


 : You have been given following code
1. sc: class Object asc: class AnotherSampleClass
2. sc: class SampleClass asc: class AnotherSampleClass
3. Access Mostly Uused Products by 50000+ Subscribers
4. sc: class AnotherSampleClass asc: class AnotherSampleClass




Correct Answer : Get Lastest Questions and Answer :
Explanation:






Related 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*/};
}





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,



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


Question : You have been given following three classes as below.'

A.java

public class A {
public void a(){}
int a;
}

B.java

public class A {
public void a(){}
int a;
}

C.java
import java.io.*;
package p1;

class A {
public void main(String filename) throws IOException {}
}

Which of the follwing statement is true, with regards to above code.

 : You have been given following three classes as below.'
1. Only the A.Java file compiles successfully.
2. Only the B.java file compiles successfully
3. Access Mostly Uused Products by 50000+ Subscribers
4. The A.Java and B.java files compile successfully
5. The B.java and C.java files compile successfully.



Question : Given the code fragment:
int[] array = {I, 2, 3, 4, 5};

And given the requirements:
1. Process all the elements of the array in the order of entry.
2. Process all the elements of the array in the reverse order of entry.
3. Access Mostly Uused Products by 50000+ Subscribers

Which two statements are true?

A. Requirements 1, 2, and 3 can be implemented by using the enhanced for loop.
B. Requirements 1, 2, and 3 can be implemented by using the standard for loop.
C. Requirements 2 and 3 CANNOT be implemented by using the standard for loop.
D. Requirement 1 can be implemented by using the enhanced for loop.
E. Requirement 3 CANNOT be implemented by using either the enhanced for loop or the standard for loop.

 : Given the code fragment:
1. B,D
2. A,E
3. Access Mostly Uused Products by 50000+ Subscribers
4. C,E




Question : You have been given below java Application code, when you execute it. What would be printed.

public class CalculationApp {
public static void main(String[] args) {
int var1 =200;
System.out.print(doCalc(var1));
System.out.println(" "+ var1);
}

static int doCalc(int var1){
var1= var1*2;
return var1;

}
}

 : You have been given below java Application code, when you execute it. What would be printed.
1. 400 200
2. 200 200
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails.