🎓 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 (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In Oracle Java Certification Exam Sample Questions - Part 2, we have seen a few Oracle Java Certification exam sample questions. In part 3, we will see a few more sample questions which will help to prepare for the exam.
Check out Part 1 - Oracle Java Certification Exam Sample Questions - Part 1.
Check out Part 2 - Oracle Java Certification Exam Sample Questions - Part 2.
1. Given:
public class App {
static void doCalc(byte...a) {
System.out.print("byte...");
}
static void doCalc(long a, long b) {
System.out.print("long, long");
}
static void doCalc(Byte s1, Byte s2) {
System.out.print("Byte, Byte");
}
public static void main(String[] args) {
byte b = 5;
doCalc(b, b);
}
}
A. byte…
B. long, long
C. Byte, Byte
D. compilation error
Answer
B. long, long
2. Which code fragment correctly assigns a numeric literal?
A)
byte b1 = b1011;
B)
byte b2 = 1011b;
C)
byte b3 = 0b1001;
D)
byte b4 = 0xb001;
Answer
C)
byte b3 = 0b1001;
3. Given the fragment:
public class MathFun {
public static void main(String[] args) {
int number1 = 0b0111;
int number2 = 0111_000;
System.out.println("Number1: " + number1);
System.out.println("Number2: " + number1);
}
}
What is the result?
A)
Number1: 7
Number2: 7
B)
Number1: 7
Number2: 111_000
C)
Number1: 0b0111
Number2: 0111000
D) Compilation fails
Answer
A)
Number1: 7
Number2: 7
4. What is the output of the following program?
public class Test {
public static void main(String[] args) {
String s1 = "hello";
String s2 = new String("hello");
s2 = s2.intern();
System.out.println(s1 == s2);
}
}
a) false
b) true
c) None
Answer
b) true
Explanation: We know that the intern() method will return the String object reference from the string pool since we assign it back to s2 and now both s1 and s2 are having the same reference. It means that s1 and s2 references pointing to the same object.
5. Consider the following program and choose the correct option from the list of options:
class Base {
public void test() {
}
}
class Base1 extends Base {
public void test() {
System.out.println("Base1");
}
}
class Base2 extends Base {
public void test() {
System.out.println("Base2");
}
}
class Test {
public static void main(String[] args) {
Base obj = new Base1();
((Base2) obj).test(); // CAST
}
}
a) The program will print the following: Base1.
b) The program will print the following: Base2.
c) The compiler will report an error in the line marked with comment CAST.
d) The program will result in an exception (ClassCastException).
Answer
d) The program will result in an exception (ClassCastException).
Explanation: The dynamic type of variable obj is Base1 that you were trying to cast into Base2. This is not supported and so results in an exception.
Check out Part 1 - Oracle Java Certification Exam Sample Questions - Part 1.
Check out Part 2 - Oracle Java Certification Exam Sample Questions - Part 2.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
🆕 High-Demand
80–90% OFF
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
🆕 High-Demand
80–90% OFF
ChatGPT + Generative AI + Prompt Engineering for Beginners
🚀 Trending Now
80–90% OFF
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
🌟 Top Rated
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
🌟 Top Rated
80–90% OFF
Testing Spring Boot Application with JUnit and Mockito
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Master Spring Data JPA with Hibernate
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
🎓 Student Favorite
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Comments
Post a Comment
Leave Comment