Premium

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



Question : You have been given below code

public class Test {

public static void main(String[] args) {
int numsl[] = new int[3];
int nums2[] = { 1, 2, 3, 4, 5 };
numsl = nums2;
for (int x : numsl) {
System.out.print(x + " : ");
}
}
}

What would be the result?

  : You have been given below code
1. 1:2:3:4:5:
2. 1:2:3:
3. Access Mostly Uused Products by 50000+ Subscribers
4. An ArrayoutofBoundsException is thrown at runtime.



Correct Answer : Get Lastest Questions and Answer :





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

public class Product {
int id;
String name;

public Product(int id, String name) {
this.id = id;
this.name = name;
}

public static void main(String[] args) {

// And given the code fragment:
Product p1 = new Product(101, "Pen");
Product p2 = new Product(101, "Pen");
Product p3 = p1;

boolean ansl = p1 == p2;
boolean ans2 = p1.name.equals(p2.name);
System.out.print(ansl + ":" + ans2);

}
}

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



Correct Answer : Get Lastest Questions and Answer :






Question : Given the following classes:

public class Director extends Manager {
public int stockOptions;
}

public class Manager extends Employee {
public int budget;
}

public class Employee {
public int salary;


public static void main(String[] args) {
Employee employee = new Employee();
Manager manager = new Manager();
Director director = new Director();
// line n1
}
}

Which two options fail to compile when placed at line n1 of the main method?

A. employee.salary = 50_000;
B. director.salary = 80_000;
C. employee.budget = 200_000;
D. manager.budget = 1_000_000;
E. manager.stockOption = 500;
F. director.stockOptions = 1_000;


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



Correct Answer : Get Lastest Questions and Answer :

Explanation:



Related 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();





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.






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







Question : You have been given below code

default void hadoopexam(){}

Which statement is true?


 : You have been given below code
1. This method is invalid.
2. This method can be used only in an interface.
3. Access Mostly Uused Products by 50000+ Subscribers
4. This method can be used only in an interface or an abstract class.
5. None of above.







Question : Which statement initializes a stringBuilder to a capacity of ?

 : Which statement initializes a stringBuilder to a capacity of ?
1. StringBuilder sb = new String ("128");
2. StringBuilder sb = StringBuilder.setCapacity (128);
3. Access Mostly Uused Products by 50000+ Subscribers
4. StringBuilder sb = new StringBuilder (128);