Premium

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



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



Correct Answer : Get Lastest Questions and Answer :
Explanation: The while statement is incorrect. It has the syntax of a for statement.
The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as:
while (expression) {
statement(s)
}
The while statement evaluates expression, which must return a boolean value. If the expression evaluates to true, the while statement executes the statement(s) in the while block.
The while statement continues testing the expression and executing its block until the expression evaluates to false







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



Correct Answer : Get Lastest Questions and Answer :
Explanation:






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





Correct Answer : Get Lastest Questions and Answer :
Explanation:



Related Questions


Question : Please look into given code fragement.
Which of the following conditional statement will help
you to print Equal ?
  : Please look into given code fragement.
1. String firstString = secondString;
if(firstString==secondString)
2. if(firstString.equlaIgnoreCase(secondString))
3. String thirdString = secondString;
if(firstString.equals(thirdString));
4. if(firstString.toLowerCase() == str2.toLowerCase())




Question : You have been given below code fragement

StringBuilder sb = new StringBuilder ( ) ;
sb.append ("world");

Which code fragment prints Hello World?

  :   You have been given below code fragement
1. sb.insert(0,"Hello "); System.out.println(sb);
2. sb.append(0,"Hello "); System.out.println(sb);
1. sb.add(0,"Hello "); System.out.println(sb);
2. sb.set(0,"Hello "); System.out.println(sb);





Question : Given the code fragment:
String h1 = "Bob";
String h2 = new String ("Bob");
What is the best way to test that the values of h1 and h2 are the same?

  : Given the code fragment:
1. if (h1 = = h2)
2. if (h1.equals(h2))
3. if (h1 = = h2)
4. if (h1.same(h2))



Question : You have been given belwo interface declaration

interface Runnable {
public voide run();
}

Which of the following will create instance of Runnable type?

   : You have been given belwo interface declaration
1. Runnable run = 0 -> {
System.out.println("Run");
}
2. Runnable run = 0 -> System.out.println("Run");
3. Runnable run = 0 > System.out.println("Run");
4. Runnable run => System.out.println("Run");
5. None of above





Question : You have been given below Java Code

public class Painting {
private String type;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public static void main(String[] args) {
Painting obj1 = new Painting();
Painting obj2 = new Painting();
obj1.setType(null);
obj2.setType("Fresco");
System.out.print(obj1.getType() + " : " + obj2.getType());
}
}

When you run it, what would be printed ?


   : 	You have been given below Java Code
1. : Fresco
2. null : Fresco
3. Fresco : Fresco
4. A NullPointerException is thrown at runtime





Question : You have been given below code

boolean log3 = (5.0 != 6.0) && (4 != 5);
boolean log4 = (4 != 4) || (4 == 4);
System.out.println("\n log3:" + log3 + "\n log4 : " + log4);

When you execute this code, what would be printed ?
   : 	You have been given below code
1. log3:false
log4:true
2. log3:true
log4:true
3. log3:true
log4:false
4. log3:false
log4:false