Premium

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



Question : You have been given following code

public class Testoperator {
public static void main(String[] args) {
int result = 30 - 12 / (2 * 5) + 1;
System.out.print("Result = " + result);
}
}

What is the result?


 : You have been given following code
1. Result = 2
2. Result = 3
3. Result = 28
4. Result = 29
4. Result = 30




Correct Answer : Get Lastest Questions and Answer :





Question : Which three are bad practices?

A. Checking for ArrayIndexoutofBoundsException when iterating through an array to determine when all elements have been visited
B. Checking for Error and. If necessary, restarting the program to ensure that users are unaware problems
C. Checking for FileNotFoundException to inform a user that a filename entered is not valid
D. Checking for ArrayIndexoutofBoundsException and ensuring that the program can recover if one occur
E. Checking for an IoException and ensuring that the program can recover if one occurs

 : Which three are bad practices?
1. A,B,C
2. B,C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,B,D
5. B,C,D



Correct Answer : Get Lastest Questions and Answer :
Explanation:







Question : You have been given following code fragment

String[] cartoons = { "tom", "jerry", "micky", "tom" };
int counter = 0;
if ("tom".equals(cartoons[0])) {
counter++;
} else if ("tom".equals(cartoons[1])) {
counter++;
} else if ("tom".equals(cartoons[2])) {
counter++;
} else if ("tom".equals(cartoons[3])) {
counter++;
}
System.out.print(counter);

What would be printed , when executed ?
 : You have been given following code fragment
1. 1
2. 2
3. Access Mostly Uused Products by 50000+ Subscribers
4. 0




Correct Answer : Get Lastest Questions and Answer :
Explanation: Counter++ will be executed only once because of the else if constructs.





Related Questions


Question : You have been given below code. Which is a correct statement ?

ArrayList list = new ArrayList<>(1);
list.add(1001);
list.add(1002);
System.out.println(list.get(list.size()));

 : You have been given below code. Which is a correct statement ?
1. Compilation fails due to an error on line 1
2. An exception is thrown at run time due to error on line 3
3. Access Mostly Uused Products by 50000+ Subscribers
4. 1002



Question : Which statement is/are true?
I. Default constructor only contains "super();" call.
II. We can't use any access modifier with a constructor.
III. A constructor should not have a return type.

  : Which statement is/are true?
1. Only I.
2. Only II.
3. Access Mostly Uused Products by 50000+ Subscribers
4. Only I and III.

5. ALL I, II, III






Question : You have been given following code

public class Student {
public String name = "";
public int age = 0;
public String major = "Undeclared";
public boolean fulltime = true;

public void display() {
System.out.println("Name: " + name + " Major: " + major);
}

public boolean isFullTime() {
return fulltime;
}
}


public class TestStudent {
public static void main(String[] args) {
Student bob = new Student();
bob.name = "Bob";
bob.age = 18;
bob.year = 1982;
}
}

What is the result?

 : You have been given following code
1. year is set to 1982.
2. bob.year is set to 1982
3. Access Mostly Uused Products by 50000+ Subscribers
4. A compile time error is generated.




Question : You have been given following code

public class MyClass {
public static void main(String[] args) {
while(int ii = 0; ii < 2) {
ii++;
System.out.println("ii = " + ii);
}
}
}

What would be result ?


 : You have been given following code
1. ii = 1 ii = 2
2. Compilation fails
3. Access Mostly Uused Products by 50000+ Subscribers
4. The program goes into an infinite loop with no output
5. The program goes to an infinite loop outputting: ii = 1 ii = 1




Question : You have been given following

class Base {
public static void main(String[] args) {
System.out.println("Base " + args[2]);
}
}

public class Sub extends Base {
public static void main(String[] args) {
System.out.println("Overriden " + args[1]);
}
}

 : You have been given following
1. Base 30
2. Overridden 20
3. Access Mostly Uused Products by 50000+ Subscribers
4. Base 30 Overridden 20




Question : You have been given following code

public class ScopeTest {
int j;
int k;

public static void main(String[] args) {
new ScopeTest().doStuff();
}

void doStuff() {
int x = 5;
doStuff2();
System.out.println("x");
}

void doStuff2() {
int y = 7;
System.out.println("y");
for (int z = 0; z < 5; z++) {
System.out.println("z");
System.out.println("y");
}
}
}

Which two items are fields?

A. j
B. k
C. x
D. y
E. z


 : You have been given following code
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,B,C