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 : Which of the following exception will be thrown due to the statement given here?
int array[]= new int[-2];


 : Which of the following exception will be thrown due to the statement given here?
1. NullPointerException
2. NegativeArraySizeException
3. Access Mostly Uused Products by 50000+ Subscribers
4. IndexOutOfBoundsException
5. This statement does not cause any exception




Question : You have been given following code snippet

float x = 22.00f % 3.00f;
int y = 22 % 3;
System.out.print(x + ", " + y);

What is the result?


 : You have been given following code snippet
1. 1.0, 1
2. 1.0f, 1
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails
5. An exception is thrown at runtime




Question : You have been given following code

package p1;

public class Test {
static double dvalue;
static Test ref;

public static void main(String[] args) {
System.out.println(ref);
System.out.println(dvalue);
}
}

What is the result?


 : You have been given following code
1. p1.Test.class 0.0
2. 0.000000
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails
5. A NullPointerException is thrown at runtime




Question : You have been given following code

class StaticField {
static int i = 7;

public static void main(String[] args) {
StaticField obj = new StaticField();
obj.i++;
StaticField.i++;
obj.i++;
System.out.println(StaticField.i + " " + obj.i);
}
}

what would be printed ?


 : You have been given following code
1. 10 10
2. 8 9
3. Access Mostly Uused Products by 50000+ Subscribers
4. 7 10




Question : Which declaration initializes a boolean variable?

 : Which declaration initializes a boolean variable?
1. boolean h = 1;
2. boolean k = 0;
3. Access Mostly Uused Products by 50000+ Subscribers
4. boolean j = (1 < 5);




Question : Which two are Java Exception classes?
A. SercurityException
B. DuplicatePathException
C. IllegalArgumentException
D. TooManyArgumentsException

 : Which two are Java Exception classes?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. A,C