
Java Foundations 1Z0-811 Free Practice Questions
Prepare for your education or career advancement with these practice questions for the Oracle Certified Foundations Associate, Java exam. This certification, also known as 1Z0-811, verifies your understanding of core Java concepts and skills, making you a valuable asset to any company. This credential is particularly targeted towards students in two-year colleges, secondary schools, and universities who have participated in the Oracle Academy program or are studying computer science with a focus on Java.
By completing these practice questions, which are based on the 1Z0-811 Practice Tests Study Plan by MyExamCloud, you can become familiar with the exam format and content. This will increase your chances of success on the certification exam. Additionally, the explanations provided in the 1Z0-811 Java Foundations Free Practice Mock Exam can serve as a comprehensive review of essential concepts for the exam.
Obtaining the Oracle Certified Foundations Associate, Java certification demonstrates your proficiency in Java programming and can pave the way for further education and career opportunities. It is a valuable credential for those beginning their Java journey or looking to advance their skills and knowledge in the field. Prepare for success with these practice questions and start your journey towards becoming a certified Java professional.
Topic:Java Basics
QUESTION: 1
Consider the following code:
class MyExamCloud {
public static void main(String[] args) {
for (int i = 0; i<args.length; i++)
System.out.print(args[i]);
}
}
What will be the output when it is run by giving the following command:
java MyExamCloud welcome to Java!
A:Welcome to Java!
B:Welcome
to
Java!
C:WelcometoJava!
D:Welcome
to
E:Welcometo
F:Welcome to
ANSWER: Choice C
Topic:Java Basics
QUESTION: 2
Java is platform independent.
II. Java is OOP language.
III. java is strong typed programming language
Which of the following/followings is true about java?
A:Only I.
B:Only II.
C:Only I and II.
D:Only II and III.
E:All of above.
ANSWER: Choice E
Topic:Java Basics
QUESTION: 3
Given:
package com.myexamcloud;
public class StudyPlan {
// code here
}
Which one of the following option correctly applies encapsulation principle for StudyPlan class?
A:
private String name;
public void setName(String name) {
this.name = name;
}
pubic String getName() {
return name;
}
B:public class StudyPlan {
public String name;
pubic String getName() {
return name;
}
C: public String name;
pubic String getName() {
return name;
}
D:final String name;
pubic String getName() {
return name;
}
E:static String name;
public void setName(String name) {
this.name = name;
}
pubic String getName() {
return name;
}
ANSWER: Choice A
Topic:Java Basics
QUESTION: 4
You have successfully compiled and generated .class files of your Birthday Wishes app in Windows platform.
What is true about Birthday Wishes app ?
A:Birthday Wishes app byte code can run only on Windows without JVM.
B:Birthday Wishes app byte code can run on any OS if there is a JRE available for that OS.
C:Birthday Wishes app byte code can run on any OS without JVM.
D:Reminder app byte code must be converted to native code to run on any other OS.
E:Birthday Wishes app byte code must be converted to native code to run on any other OS.
ANSWER: Choice B
Topic:What Is Java?
QUESTION: 5
I. One source code file can include more than one class.
II. Package statement should come before class and import statements.
III. One source code file can include more than one package.
Which is/are true based on the above scenario?
A:Only II.
B:Only III.
C:Only I and II.
D:Only I and III.
E:None.
ANSWER: Choice C
Topic:What Is Java?
QUESTION: 6
Which of the following/followings is true about java?
A:Source code file can have only one public class.
B:Source code can contains only one class.
C:Source code may contain more than one package statement.
D:Source code name should have .class extention.
E:All of above.
ANSWER: Choice A
Topic:Basic Java Elements
QUESTION: 7
Given:
1. import java.util.Random;
2. import java.lang.System;
3. import java.util.*;
4. import java.lang.*;
5.
6. public class MyExamCloud {
7.
8. public static void main(String[] args) {
9. Random r = new Random();
10. System.out.println(r.nextInt(10));
11.
12. }
13.}
Which lines contains redundant imports that not necessary for this code to compile?
A:Online lines 1 and 2
B:Online lines 1,2 and 3
C:Online lines 2,3 and 4
D:Online lines 1,3 and 4
E:All
ANSWER: Choice C
Topic:Basic Java Elements
QUESTION: 8
You are assigned to develop Training Lab product in EPractize Labs. The project team is splitted based on modules and each module Java files are well packaged by Java packages.
Which of the following import statements are legal to import com.epractizelabs.traininglab.util.MenuBuilder class?
A:import com.epractizelabs.traininglab.util.*;
B:import com.epractizelabs.traininglab.util.MenuBuilder;
C:import com.epractizelabs.traininglab.util;
ANSWER: Choice A,Choice B
Topic:Classes and Constructors
QUESTION: 9
Consider the following class:
class Exam{ }
Which of the following constructor can be used for above class?
A:exam(){ super();}
B:final Exam(){}
C:public Exam(){ }
D:Any of above
ANSWER: Choice C
Topic:Java Methods
QUESTION: 10
You are asked to create a method which should satisfy the following requirements.
We should able to call method without an instance reference. Method should return integer array. It should not available to other packages. Method name should be "change".
Which is the correct method signature?
A:static void change(int[] c)
B:static int[] change()
C:protected int[] change()
D:protected void change(int[] a)
E:public int[]change ()
ANSWER: Choice B
Topic:Java Methods
QUESTION: 11
Which of the following doesn't have same method signature as others?
A:public int calculate(double x,int y)
B:public double calculate(double x,int y)
C:public void calculate(double x,int y)
D:public int calculate(int x,double y)
E:public String calculate(double x,int y)
ANSWER: Choice D
Topic:Working with Java Data Types
QUESTION: 12
Code:
1. public class MyExamCloud{
2. static int x = 16;
3. public static void main(String args[]){
4. MyExamCloud mec = new MyExamCloud ();
5. mec.x = 4;
6. int y = x/mec.x;
7. System.out.print("y = ");
8. System.out.print();
9. System.out.print(y);
10. }
11. }
What will be the result?
A:y = 1
B:y = 2
C:y = 4
D:An exception is thrown.
E:Compilation fails due to an error on line 8.
ANSWER: Choice E
Topic:Working with Java Data Types
QUESTION: 13
Which of the following statement is TRUE?
A:Local variables can be declared as public.
B:Local variables can be declared as final.
C:Local variables can be declared as private.
D:Local variables can be declared as static.
ANSWER: Choice B
Topic:Working with Java Data Types
QUESTION: 14
Which of the following variables can be defined in an interface?
A:final private static String name = "Hello";
B:String name = "Hello";
C:final protected static String name = "Hello";
D:final public static String name = "Hello";
ANSWER: Choice B,Choice D
Topic:Working with Java Data Types
QUESTION: 15
Consider following interface:
1. interface Movable {
2. static int speed = 12;
3. String s = "speed: ";
4. }
Which of the following is a valid statement?
A:new Movable().s;
B:Movable.speed = 10;
C:System.out.println(Movable.s);
D:Given interface is invalid.
ANSWER: Choice C
Topic:Working with the String Class
QUESTION: 16
Which code can convert the following String into an int variable?
String accountId = "189";
A:Integer.valueOf(accountId);
B:Integer.getInt(accountId);
C:Integer.parseInt(accountId);
D:Integer.intValue(accountId);
ANSWER: Choice C
Topic:Using Looping Statements
QUESTION: 17
Which of the following will compile successfully?
A:for(int j = 0,int k=5; j < k; k--) ;
B:for(;;System.out.print("a")) ;
C:for();
D:for(int k = 10; k--; k>0 )
;
E:None of above.
ANSWER: Choice B
Topic:Working with Java Operator
QUESTION: 18
Code:
1. public class MyExamCloud{
2. public static void main(String[] args){
3. int i = 1;
4.
5. if(i++ == 1)
6. if(i++ > 2){
7. System.out.print(i);
8. }
9. else if(i++ > 3)
10. System.out.print(i);
11. else
12. System.out.println(i);
13. }
14. }
What is the result?
A:24
B:2
C:3
D:4
E:No output
F:Compilation fails
ANSWER: Choice D
Topic:Working with Java Operator
QUESTION: 19
Code:
1. class MyExamCloud {
2. public static void main(String [] args){
3. int y=10;
4. int x = 10;
5. if(x!=10 && y++==1);
6. if(y==11 | ++x==11) y+=10;
7. System.out.print(y);
8. }
9. }
What is the result?
A:11
B:10
C:20
D:21
E:Compilation fails
ANSWER: Choice C
Topic:Using Decision Statements
QUESTION: 20
Code:
1. public class MyExamCloud {
2. public static void main(String[] args) {
3.
4. String in = "OCAJP";
5. final String cs = "ocajp";
6.
7. switch(in){
8. default : System.out.println("default");
9. case cs : System.out.println("ocajp");break;
10. case "OCAJP" : System.out.println("OCAJP");break;
11. case "OCPJP" : System.out.println("OCPJP ");break;
12. }
13. }
14.}
What is the output?
A:default ocajp
B:OCAJP
C:ocajp
D:OCPJP
E:Compilation fails.
ANSWER: Choice B
Topic:Using Decision Statements
QUESTION: 21
Which of the following 'if statements' are valid?
A:if(200+100)
B:Boolean b=false; if(b=true)
C:if("true")
D:if(new Integer(0).booleanValue())
E:boolean b=true; if(b)
ANSWER: Choice B,Choice E
Topic:Working with the Random and Math Classes
QUESTION: 22
You need to generate random numbers between 0 and 100. Which Java Class can achieve this goal?
A:java.util.Math
B:java.lang.Object
C:java.lang.Integer
D:java.lang.Random
E:java.util.Random
ANSWER: Choice E
Topic:Debugging and Exception Handling
QUESTION: 23
Which of the following is true?
A:We must have a finally clause for a try block.
B:We can't nest few try/catch blocks.
C:It is optional to use catch for a try block.
D:None of above.
ANSWER: Choice C
Topic:Debugging and Exception Handling
QUESTION: 24
Code :
class MyException extends Exception {}
class MyException2 extends MyException {}
class MyException3 extends RuntimeException {}
Based on the above code select the order of exceptions that can be catched in a try/catch block.
A:MyException2, MyException, MyException3, Exception
B:MyException, MyException2, MyException3, Exception
C:MyException3, MyException, MyException2, Exception
D:MyException, MyException3, MyException2, Exception
ANSWER: Choice A
Topic:Using Looping Statements
QUESTION: 25
Code:
1. class MyExamCloud{
2.
3. public static void main(String[] args){
4. byte count = 0;
5. while (true) {
6. System.out.println( count++ +"");
7. }
8. }
9. }
Which is the output?
A:Prints 0 to 127
B:Infinite loop prints nothing
C:Prints 0 to 127 and -128 to 0 once
D:Infinite loop prints 0 to 127 and -128 to 0
E:Compilation fails.
ANSWER: Choice D
Topic:Using Looping Statements
QUESTION: 26
Code:
1. public class MyExamCloud{
2. public static void main(String[] args){
3.
4. int[] numbers = {1,2,3,4,5};
5. // insert here
6. System.out.print(i);
7. }
8. }
Which insert at line 5, will provide following output?
12345
A:for(int i : numbers);
B:for(int i ; numbers)
C:for(i : numbers)
D:for(numbers : int i)
E:for(int i : numbers)
ANSWER: Choice E
Topic:Arrays and ArrayLists
QUESTION: 27
Code :
class Test {
public static void main(String args[]) {
int[] i = { 1, 2, 3, 4, 5 };
float[] j = new float[5];
for (int k = 0; k<j.length(); k++) {
i[k] = (char) j[k];
System.out.println(i[k]);
}
}
}
What will be the result of an attempt to compile and run this program?
A:Compiler error - char cannot be assigned to int
B:Compiler error - Array j is not initialized
C:ArrayIndexOutOfBoundsException at runtime
D:Prints 0 five times
E:Prints 0.0 five times
F:Compilation error
ANSWER: Choice F
Topic:Classes and Constructors
QUESTION: 28
Code:
1. class MyExamCloud {
2. //What would be correct constructor for this class
3. }
What would be correct constructor for the MyExamCloud class?
A:private MyExamCloud (int x){ }
B:MyExamCloud MyExamCloud (){ }
C:void MyExamCloud (String s){ }
D:final MyExamCloud (){ System.out.print("Java Junior"); }
E:MyExamCloud (){ System.out.print("Java Junior");
super();
}
ANSWER: Choice A
Author | JEE Ganesh | |
Published | 7 months ago | |
Category: | Java Certification | |
HashTags | #Java #JavaCertification |