The following code contains a syntax or logic error. Explain the error and show
ID: 3861778 • Letter: T
Question
The following code contains a syntax or logic error. Explain the error and show how to correct it. Line 1 public interface Interface 1 Line 2 {Line 3 public int methodB(int b) {System.out.println(b);} Line 4} The following code contains a syntax or logic error. Explain the error and show how to correct it. Line 1 public class Salamander extends Animal, Amphibian implements Feedable Line 2 {Line 3 String name; Line 4 public Salamander(String name) (ellipsis) Line 5 public String getName(){ellipsis} Line 6//ellipsis more here Line 7}Explanation / Answer
Question 1:
Answer:
Interfaces can contain only abstract method not a concrete method. Interface should have a method delarations not a implementation. I have corrected the code below.
public interface Interface1 {
publi cint methodB(int b);
}
Question 2:
Answer:
Java does not support multiple inheritance. If we want to implement we have to go for Interfaces.
public class Salamander extends Animal implements Feedable, Amphibian {
String name;
public Salamander(String name) {
}
public Strign getName() {
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.