📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In this part 1 of the Oracle Java Certification Exam Sample Questions series, you can check out a few sample questions for reference for ava SE 8 Oracle Certified Associate (OCA) certification.
The answer to each question has given at end of this post.
Check out Part 2 - Oracle Java Certification Exam Sample Questions - Part 2.
Check out Part 3 - Oracle Java Certification Exam Sample Questions - Part 3
1. Given the code fragment:
public class App {
void calcBill() {
// Line n1
new Invoice().print();
}
}
private class Invoice {
void print() {System.out.println("Invoice Printed");}
}
public class Invoice {
void print() {System.out.println("Invoice Printed");}
}
class Invoice {
void print() {System.out.println("Invoice Printed");}
}
protected class Invoice {
void print() {System.out.println("Invoice Printed");}
}
2. Given
public interface Test {
public void method1() {
System.out.println("method1");
}
public
default void method2() {
System.out.println("method2");
}
public static void method3() {
System.out.println("method3");
}
public abstract void method4();
}
3. Given the code fragment:
import java.util.Arrays;
public class App {
public static void main(String[] args) {
String[] fruits = {
"banana",
"apple",
"pears",
"grapes"
};
Arrays.sort(fruits, (a, b) -> a.compareTo(b));
for (String s: fruits) {
System.out.print(" " + s);
}
}
}
4. Given the code fragment:
import java.util.stream.Stream;
public class App {
public static void main(String[] args) {
Stream < Integer > nums = Stream.of(1, 2, 3, 4, 5);
nums.filter(n -> n % 2 == 1);
nums.forEach(p -> System.out.print(p));
}
}
5. Given the code fragment:
import java.io.Closeable;
import java.io.IOException;
class MyResource1 implements Closeable {
public void close() {
System.out.print("r1 ");
}
}
class MyResource2 implements AutoCloseable {
public void close() throws IOException {
System.out.print("r2 ");
throw new IOException();
}
}
public class App {
public static void main(String[] args) {
try (MyResource1 r1 = new MyResource1(); MyResource2 r2 = new MyResource2();) {
System.out.print("try ");
} catch (Exception e) {
System.out.print("catch ");
for (Throwable t: e.getSuppressed()) {
System.out.println(t.getClass().getName());
}
}
}
}
Answers
1. C2. C
3. A
4. D
5. B
Check out Part 2 - Oracle Java Certification Exam Sample Questions - Part 2.
Check out Part 3 - Oracle Java Certification Exam Sample Questions - Part 3
Comments
Post a Comment
Leave Comment