Lpu Cse310 Day 4 Ca3 Slot 2 Set 1
Lpu Cse310 Day 4 Ca3 Slot 2 Set 1
No. of Sections: 1
Total Questions: 15
Total Duration: 40 mins
No. of Questions: 15
Duration: 40 mins
Q1) Fill in the blanks to create a functional interface and use lambda. Output: Sum is: 45
Code Snippet
interface Adder {
int __________(int a, int b);
}
Q2) Fill in the blanks to check if the sum of two variables is divisible by 7 and 5. Output: Divisible
by 7 and 5
Code Snippet
public class Main {
public static void main(String[] args) {
int a = 35, b = 70, sum = a + b;
if(__________________ && ________________) {
System.out.println("Divisible by 7 and 5");
}
}
}
Q3) Fill in the blanks to overload method that prints employee details. Output: ID: 1001, Name:
Meena ID: 1002, Name: Raj, Department: Sales
Code Snippet
class Employee {
void display(int id, String name) {
System.out.println("ID: " + id + ", Name: " + name);
}
Q4) Fill in the blanks where local class prints its method with enclosing method’s name. Output:
Inside display(), local method called
Code Snippet
public class Scope {
void display() {
class Inner {
void localMethod() {
System.out.println("Inside display(), local method __________");
}
}
Inner i = new Inner();
i.__________();
}
Q5) Replace the error to print the current month using Calendar. Expected Output: (0-based index for
month, e.g., 3 for April)
Code Snippet
import java.util.Calendar;
class CalTest {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
System.out.println(cal.MONTH); // Error
}
}
Options
1) cal.get(Calendar.MONTH)
2) cal.MONTH()
3) cal.getMonth()
4) Calendar.getMonth()
Q6) Identify the correct replacement for the marked issue so that the program prints "20."
Code Snippet
public class Cart {
public static void main(String[] args) {
int result = (10 - 2 + 4) * 3; // Issue
System.out.println(result);
}
}
Options
1) int result = 10 - 2 * 4 * 3;
2) int result = 10 - (2 - 4) * 3;
3) int result = (10 - 2 * 4) /3;
4) int result = 10 - (2 - 4 * 3);
Q7) Identify the correct replacement for the marked issue so the program prints only "Affordable".
Code Snippet
public class Cart {
public static void main(String[] args) {
int price = 150;
if (price > 100) // Issue
System.out.println("Expensive");
System.out.println("Affordable");
}
}
Options
1) if (price = 100)
2) if (price == 100)
3) if (price >= 100)
4) if (price < 100)
Q8) Identify the correct replacement for the marked issue so that the program prints "Bark"
Code Snippet
interface Animal {
default void sound() {
System.out.println("Some sound");
}
}
class Test {
public static void main(String[] args) {
Dog dog = new Dog();
dog.sound();
}
}
Options
1) public void sound() {
2) private void sound() {
3) protected void sound() {
4) default void sound() {
Q9) Arrange the code where a subclass calls its parent class constructor using super.
Code Snippet
1. System.out.println("Animal Constructor");
2. System.out.println("Dog Constructor");
3. Dog() {
4. class Dog extends Animal {
5. public class Main {
6. public static void main(String[] args) {
7. Dog d = new Dog();
8. class Animal {
9. Animal() {
}
}
}
}
}
}
Options
1) 8, 9, 1, 4, 3, 2, 5, 6, 7
2) 8, 1, 9, 4, 2, 3, 5, 6, 7
3) 4, 3, 2, 8, 9, 1, 5, 6, 7
4) 8, 9, 4, 3, 1, 2, 5, 6, 7
Q10) Arrange the code to override a method in child class and call it through parent reference.
Code Snippet
1. Parent ref = new Child();
2. void display() {
3. class Child extends Parent {
4. System.out.println("Child Display");
5. public static void main(String[] args) {
6. ref.display();
7. System.out.println("Parent Display");
8. class Parent {
9. public class Main {
}
}
}
}
}
}
Options
1) 8, 2, 7, 3, 2, 4, 9, 5, 1, 6
2) 3, 2, 4, 8, 2, 7, 9, 5, 1, 6
3) 8, 2, 3, 4, 9, 1, 5, 6, 7
4) 9, 5, 1, 6, 8, 2, 7, 3, 2, 4
Q11) Arrange the following lines of code to determine if this year is a leap year
Code Snippet
import java.time.*;
public class LeapYearChecker {
1. LocalDate today = LocalDate.now();
2. public static void main(String[] args) {
3. System.out.println("Current year: " + year);
4. System.out.println("Is " + year + " a leap year? " + isLeapYear);
5. int year = today.getYear();
6. boolean isLeapYear = today.isLeapYear();
}
}
Options
1) 2, 1, 3, 5, 6, 4
2) 2, 1, 5, 3, 6, 4
3) 2, 1, 6, 5, 3, 4
4) 2, 1, 5, 6, 3, 4
class ReadAndPrint {
public static void main(String[] args) {
1. System.out.println("You entered: " + input);
2. Scanner sc = new Scanner(System.in);
3. String input = sc.nextLine();
4. sc.close();
}
}
Options
1) 3 2 4 1
2) 2 3 1 4
3) 3 2 1 4
4) 2 1 3 4
Options
1) A, C
2) B, C
3) A, D
4) C, D
Person(String name) {
this.name = name;
}
}
Options
1) A, B, C
2) A, D
3) B, C, D
4) A, B, C,D
Q15) Which of the following Java programs will compile and output 15?
A.
public class Test {
public static void main(String[] args) {
int a = 10 + 5;
System.out.println(a);
}
}
B.
public class Test {
public static void main(String[] args) {
int a = 30 / 0;
System.out.println(a);
}
}
C.
public class Test {
public static void main(String[] args) {
int a = 20 - 5;
System.out.println(a);
}
}
D.
public class Test {
public static void main(String[] args) {
int a = 3 * 5;
System.out.println(a);
}
}
Options
1) A, B, C
2) B, C, D
3) A, C, D
4) A, B, D