Which of the following method compiles?*public int methodE() { }public static methodC() {}public int methodD() { return 9.0;}public void methodA() { return;}public void methodB() { return null;}
Question
Which of the following method compiles?*public int methodE() { }public static methodC() {}public int methodD() { return 9.0;}public void methodA() { return;}public void methodB() { return null;}
Solution
The following methods will compile:
public void methodA() { return;}: This method will compile because it is a void method (doesn't return a value) and it has a return statement with no value, which is allowed in void methods.
The following methods will not compile:
-
public int methodE() { }: This method won't compile because it is supposed to return an integer value but there is no return statement. -
public static methodC() {}: This method won't compile because it lacks a return type. In Java, every method declaration must have a return type. -
public int methodD() { return 9.0;}: This method won't compile because
Similar Questions
Which of the following declares an abstract method in an abstract Java class? _____A. public abstract method(); B. public abstract void method(); C. public void abstract method(); D. public void method() {}
Which of the following is an example of a non-static method? (Select whichever applicable)Question 9Answera.void displayMessage() {}b.public static void printName() {}c.public void calculateSum() {}d.private static int x = 10;
public class Code { public static void main(String[] args) { method(null); } public static void method(Object o) { System.out.println("Object method"); } public static void method(String s) { System.out.println("String method"); }}
Which of the following method declarations is correct for a static method named displayFacts() if the method receives an int argument? a. public static int displayFacts() b. public void displayFacts(int data) c. public static void displayFacts(int data) d. public void displayFacts(static int)
Which of the following is the correct way to declare a method in Java?Question 20Answera.int myMethod( ) { }b.void myMethod { }c.myMethod( ) { }d.int myMethod;
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.