Java Question
Please highlight the 1 correct option from 4 given at bottom
Which code snippets are valid return statements for method1() and method2()?
public void method1(){
// CODE SNIPPET 1
}
public Float method2(){
// CODE SNIPPET 2
}
return null; for CODE SNIPPET 1 and return 12.3; for CODE SNIPPET 2
return; for CODE SNIPPET 1 and return null; for CODE SNIPPET 2
return null; for both CODE SNIPPET 1 and CODE SNIPPET 2
return; for CODE SNIPPET 1 and return 12.3; for CODE SNIPPET 2
Here is the answer..
option D is the correct one because CODE SNIPPET1 void means it doesn't return anything and CODE SNIPPET2 return type Float.
If we want to return null from the CODE SNIPPET1 we need to write return type as Object.
Here is the code sample for reference:


If you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP...
Java Question Please highlight the 1 correct option from 4 given at bottom Which code snippets...
Java Question Please highlight the 1 correct option from 4 given at bottom What method signature will work with this code? boolean healthyOrNot = isHealthy(“avocado”); public void isHealthy(String avocado) boolean isHealthy(String string) public isHealthy("avocado") private String isHealthy(String food)
Java Question Please highlight the 1 correct option from 4 given at bottom What code would you use to tell if "schwifty" is of type String? "schwifty".getClass().getSimpleName() == "String" "schwifty".getType().equals("String") "schwifty".getType() == String "schwifty" instanceof String
java
Use the classes given in the previous question and write the output tha t is generated when this program is run. You may write your answer as "Elaine 2 Jerry 1" or "Compiler Error" or "Runtime Error" If there is an error then explain why. public class Main{ public static void main(String args[]){ Object o = new Kramer(); ((George)(o)).method1(); ((Jerry)(o)). method1(); 0.method2(); public class George extends Elaine {! public void method1() { System.out.print("George 1 "); public class Jerry {...
please answer correctly.
Language/Type Java Inheritance polymorphism Assume that the following classes have been defined: public class George extends Elaine ( public void method1() { print("George 1 "); public class Jerry { public void method10) { print("Jerry 1 "); public void method20 { print("Jerry 2 "); public String toString() { return "Jerry": public class Elaine extends Kramer public String toString() { return "Elaine " + super.toString(); public class Kramer extends Jerry public void method1() { super.method1(); print ("Kramer 1"); public...
JAVA: BASIC LINKED LISTS : Could you, please, provide SIMPLE code snippets to represent these operations? 1. Removing a data element at an index "i" 2. Removing a given data element from the end of a linked list 3. Get/find the data element at a given index
Please, explain clearly each line of code with your answers. Question 1 Consider the following code snippet: int ctr = 0; int myarray[3]; for (int i = 0; i < 3; i++) { myarray[i] = ctr; ctr = ctr + i; } cout << myarray[2]; What is the output of the code snippet? Question 2 Consider the following code snippet: int cnt = 0; int numarray[2][3]; for (int i = 0; i < 3; i++) { for (int j =...
Question 6 (1 point) What is the output of the following code snippet? Please ensure your answe. spaced according to the program code output. public static void main(String[] args) int channel = assignChannel (2); System.out.println("Channel: " + channel); ) public static int assignChannel(int channel) return channel + 3; > A/
Please answer in Java. The code that needs to be modified is below. Thank you. Question: Implement Doubly Linked List add method which add an element to a specific position. - It’s an instance method that takes a position and an element, then adds the element to this specific position and shifts the element currently at this position and any subsequent elements to the right. It throws an exception if the position is out of bound. It traverses the list...
Java Question: Can you guys please help me write below code in RECURSION. // add a key-value pair, replacing old key-value pair if key is already present public void put(K key, V val) { if (val == null) { delete(key); return; } for (Node<K,V> x = first; x != null; x = x.next) if (key.equals(x.key)) { x.val = val; return; } first = new Node<>(key, val, first); N++;...
JAVA question: Please see the code posted below and improve it so it allows for: 1.new aircraft are entered [new objects] 2.these objects are automatically be assigned their unique IDs [unique ID linked to a static class variable?] 3.will not be automatically given airport codes [initialise airportCode as null in the constructor] 4.assign an airport code to each new aircraft [an object method?] The code: class Aeroplane { static int planeCount = 0; static int codeGenerator = 0; int uniqueID...