Methods QuizS2C Home « Objects & Classes Quiz

The questions in this Java quiz are on the topics covered in the java - Objects & Classes section of the site. The table below lists the lesson used for each quiz, a description of the lesson content and the quiz number and questions associated with that lesson.

Lesson Summary

Click on a lesson in the table to go to that lesson for a refresher on the topics for that quiz.

Click on a quiz in the table to go straight to the quiz for a particular lesson.

Objects & Classes Lessons Description Quiz Info.
Lesson 1 - ArraysIn this lesson we look at arrays and how to use them in java.Quiz1
8 questions
Lesson 2 - Class Structure & SyntaxFor this lesson we looked at class structure and syntax within our Java programs.Quiz2
8 questions
Lesson 3 - Reference VariablesThis lesson is about reference variables and how to use them within our Java programs.Quiz3
7 questions
Lesson 4 - MethodsWe have used methods throughout the lessons so far so its time for a thorough investigation of what we can do with these members.This quiz.
10 questions
Lesson 5 - Instance Variables & ScopeThis lesson is about instance variables, how to use them and their scope.Quiz5
6 questions
Lesson 6 - ConstructorsIn this lesson we learn about constructors, which we can use to instantiate objects of our classes.Quiz6
7 questions
Lesson 7 - Static MembersFor this lesson we investigate what static means and how to apply it to our class members.Quiz7
6 questions
Lesson 8 - EnumerationsIn our final lesson of this section we go through enumerations which were introduced in java.Quiz8
8 questions

Java Objects & Classes Quiz 4

The quiz below tests your knowledge of the material learnt in Objects & Classes - Lesson 4 - Methods.

Question 1 : Method declarations can have up to how many components?
- Method declarations can have up to 6 components
Question 2 : The required elements of a method are the the method name, a pair of parenthesis (), a body between braces {} and?
- Methods must have a <em>return type</em>.
Question 3 : We can have more than one method with the same method name in a class?
- We can have more than one method with the same name in a class and this is known as overloading.
Question 4 : What return type is used when we don't want to return anything from a method?
- The <code>void</code> <em>return type</em> is used when we don't want to return anything from a method.
Question 5 : Is the following code snippet valid?
static void addNumbers(int ... number, String string) {
System.out.println("Total = " + string);
}
- When using <em>varargs</em> they must come last in the parameter list.
Question 6 : What do we have to be careful of when overloading methods that use varargs
- We have to be careful of ambiguity when overloading methods that use varargs. The compiler needs to resolve parameter lists to one method.
Question 7 : Is the following method declaration valid?
static void addNumbers(int ... number, String ... string) {
System.out.println("Total = ");
}
- When using <em>varargs</em> only one is allowed in the parameter list.
Question 8 : How do we pass a value back from a method
- We use the <code>return</code> keyword.
Question 9 : What are the method name and method parameters components collectively known as?
- Collectively these components are known as the method signature.
Question 10 : When we pass an argument to a method what are we are actually passing?
- When we pass an argument to a method we are actually passing a copy of the argument and this is known as <em>pass-by-value</em>
Quiz Progress Bar Please select an answer

What's Next?

The next quiz on Java Objects & Classes is all about instance variables and scope.