Premium

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



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;
}
}
Which line of code initializes a student instance?

 :You have been given following code
1. Student student1;
2. Student student1 = Student.new();
3. Access Mostly Uused Products by 50000+ Subscribers
4. Student student1 = Student();




Correct Answer : Get Lastest Questions and Answer :







Question : Which of the following will print current time?

 : Which of the following will print current time?
1. System.out.print(new LocalTime()-now);
2. System.out.print(new LocalTime());
3. Access Mostly Uused Products by 50000+ Subscribers
4. System.ouLprint(LocalTime.today());
5. None of the above.





Correct Answer : Get Lastest Questions and Answer :
Explanation: The LocalTime is an interface, so we can't use new keyword with them. So options A and C
are incorrect. To get current time we can call now method on LocalTime interface. So option
C is correct. Option D is incorrect as there is no method called today as in LocalTime
interface







Question : Given the code fragment:
String name = "Spot";
int age = 4;
String str ="My dog " + name + " is " + age;
System.out.println(str);

And
StringBuilder sb = new StringBuilder();

Using StringBuilder, which code fragment is the best potion to build and print the following string
My dog Spot is 4

A. sb.append("My dog " + name + " is " + age);
System.out.println(sb);

B. sb.insert("My dog ").append( name + " is " + age);
System.out.println(sb);

C. sb.insert("My dog ").insert( name ).insert(" is " ).insert(age);
System.out.println(sb);

D. sb.append("My dog ").append( name ).append(" is " ).append(age);
System.out.println(sb);


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






Correct Answer : Get Lastest Questions and Answer :






Related Questions


Question : You have been given below declarations:

public abstract class Animal
public interface Hunter
public class Cat extends Animalimplements Hunter
public class Tiger extends Cat

Which answer fails to compile?

  : You have been given below declarations:
1. ArrayList myList1 = new ArrayList<>();
myList1.add(new Tiger());
2. ArrayList myList2 = new ArrayList<>();
myList2.add(new Cat());
3. Access Mostly Uused Products by 50000+ Subscribers
myList3.add(new Tiger());
4. ArrayList myList4 = new ArrayList<>();
myList4.add(new Cat());
5. ArrayList myList = new ArrayList<>();
myList.add(new Cat());





Question : Which statement is true about Java byte code?
 : Which statement is true about Java byte code?
1. It can run on any platform.
2. It can run on any platform only if it was compiled for that platform.
3. Access Mostly Uused Products by 50000+ Subscribers
4. It can run on any platform that has a Java compiler.
5. It can run on any platform only if that platform has both the Java Runtime Environment and a Java compiler.






Question :

public class MarkList {
int num;

public static void graceMarks(MarkList obj4) {
obj4.num += 10;
}

public static void main(String[] args) {
MarkList obj1 = new MarkList();
MarkList obj2 = obj1;
MarkList obj3 = null;
obj2.num = 60;
graceMarks(obj2);
}
}

How many MarkList instances are created in memory at runtime?

 :
1. 1
2. 2
3. Access Mostly Uused Products by 50000+ Subscribers
4. 4






Question : You have been given below code

public class Triangle {
static double area;
int b = 2, h = 3;

public static void main(String[] args) {
double p, b, h; // line n1
if (area == 0) {
b = 3;
h = 4;
p = 0.5;
}
area = p * b * h; // line n2
System.out.println("Area is " + area);
}
}

What is the result?

  : You have been given below code
1. Area is 6.0
2. Area is 3.0
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails at line n2





Question : Given the code fragment:

public class Test {
public static void main(String[] args) {
// line n1
switch (x) {
case 1:
System.out.println("One");
break;
case 2:
System.out.println("Two");
break;

}
}
}

Which three code fragments can be independently inserted at line nl to enable the code to print one?

A. Byte x = 1;
B. short x = 1;
C. String x = "1";
D. Long x = 1;
E. Double x = 1;
F. Integer x = new Integer ("1");

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



Question : You have been given below code, what would be printed when you run it.

public class App {
public static void main(String[] args) {
Boolean[] bool = new Boolean[2];
bool[0] = new Boolean(Boolean.parseBoolean("true"));
bool[1] = new Boolean(null);
System.out.println(bool[0] + " " + bool[1]);
}
}



  : You have been given below code, what would be printed when you run it.
1. True false
2. True null
3. Access Mostly Uused Products by 50000+ Subscribers

4. A NullPointerException is thrown at runtime