IS5103 WEEK 3 QUIZ
Lesson-5 public int add(int x, int y){ int sum = x + y; return sum; } public static void main(String args[]){ Addition obj = new Addition(); int sum = obj.add(10, 20); System.out.println(“The sum of 10 and 20 is ” +…
Lesson-5 public int add(int x, int y){ int sum = x + y; return sum; } public static void main(String args[]){ Addition obj = new Addition(); int sum = obj.add(10, 20); System.out.println(“The sum of 10 and 20 is ” +…
1.How many of the following lines contain a compiler error?long min1 = 123.0, max1 = 987L;final long min2 = 1_2_3, max2 = 9 _ 8 _ 7;long min3 = 123, int max3 = 987;long min4 = 123L, max4 = 987;long…
1. Which of the following statements can be inserted in the blank so that the code will compile successfully? abstract class Snake {} class Cobra extends Snake {} class GardenSnake extends Cobra {} public class SnakeHandler { private Snake snakey; public void setSnake(Snake mySnake) { this.snakey…
1. Which of the following can fill in the blank in this code to make it compile? public class Ant { _______ void method() {} } Each correct answer represents a complete solution. Choose all that apply. A) Final Private 2. Which…
1.Which is the first line containing a compiler error?String url = “jdbc:hsqldb:file:zoo”;try (var conn = DriverManager.getConnection(url);var ps = conn.prepareStatement();var rs = ps.executeQuery(“SELECT * FROM swings”)) {while (rs.next()) {System.out.println(rs.getInteger(1));}}A) Line 3 2.Which interfaces or classes are in a database-specific JAR file?Each…
import java.io.*; import java.util.*; public class Test{ public static void main(String[] args){ Scanner in = new Scanner(System.in); String string1,string2; string1 = in.nextLine(); string2 = in.nextLine(); if(string1.equals(string2)) System.out.println(“The two strings are equal.”); else System.out.println(“The two strings are not equal.”); } }…
1.Which of the following correctly create Path instances?Each correct answer represents a complete solution. Choose all that apply.A) FileSystems.getDefault().getPath(“puma.txt”) new java.io.File(“tiger.txt”).toPath() Path.of(Path.of(“.”).toUri()) 2.Suppose that the working directory is /weather and the absolute path represents a file that exists within the…
1. What is the output of the following code snippet? 1. int temperature = 4; 2. long humidity = -temperature + temperature * 3; 3. if (temperature>=4) 4. if (humidity < 6) System.out.println(“Too Low”); 5. else System.out.println(“Just Right”); 6. else System.out.println(“Too High”); Just Right 2. What…
1.Assuming this class is accessed by only a single thread at a time, whatis the result of calling the countIceCreamFlavors() method?import java.util.stream.LongStream;public class Flavors {private static int counter;public static void countIceCreamFlavors() {counter = 0;Runnable task = () -> counter++;LongStream.range(0, 500).forEach(m…
1.Which of the following statements are true about a module containing afile named module-info.java? The content of the file is:module com.food.supplier {}Each correct answer represents a complete solution. Choose all that apply.A) No packages inside the module are automatically exported.…