Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice 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


Correct Answer : Get Lastest Questions and Answer :
Explanation:

The code compiles fine. At runtime an IndexOutOfBoundsException is thrown when the third (as value of list size=2) list item is fetched.
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)







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





Correct Answer : Get Lastest Questions and Answer :
Explanation:

Statement I is correct as the default constructor only contains super() call Statement II is incorrect as we can use any access modifier with a constructor. Statement III is correct as constructor can't have return type, even void. So option D is correct.




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.



Correct Answer : Get Lastest Questions and Answer :
Explanation:



Related Questions


Question : Given the code fragment:

public static void main(String[] args){
String date = LocalDate.parse("2014-05-04").format(DateTimeFormatter.ISo_DATE_TIME);
System.out.println(date);
}

What is the result?


 :  Given the code fragment:
1. May 04, 2014T00:00:00.000
2. 2014-05-04T00:00: 00. 000
3. 5/4/14T00:00:00.000
4. An exception is thrown at runtime.




Question : Given the code fragment:

if(aVar++ <10){
System.out.println(aVar + " Hello World!");
}else{
System.out.println(aVar + " Hello Universe!");
}

What is the result if the integer aVar is 9?


  : Given the code fragment:
1. Hello World!
2. Hello Universe!
3. Hello World
4. Compilation fails.




Question : Given

What is the result?


  : Given
1. 200.0 : 100.0
2. 400.0 : 200.0
3. 400.0 : 100.0
4. Compilation fails.





Question : Which code fragment, when inserted at line n,
enables the code to print Harish?
  : Which code fragment, when inserted at line n,
1. checkAge (iList, ( ) -> p. get Age () > 40);
2. checkAge(iList, Person p -> p.getAge() > 40);
3. checkAge (iList, p -> p.getAge() > 40);
4. checkAge(iList, (Person p) -> { p.getAge() > 40; });




Question : Given the code snippet :

When you run this code, what will be printed

  : Given the code snippet :
1. X Y Z
2. X Y Z P Q
3. X Y P Q
4. Compilation Error



Question : Please look into , given code fragement.
Select the correct options which will be printed out.

  : Please look into , given code fragement.
1. true true
2. true false
3. false false
4. false true