Static Methods QuizJ8 Home « Static Methods Quiz

The questions in this Java quiz are on the topics covered in the 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 - Array Examples & ExceptionsIn this lesson we look at some arrays examples and exceptions.Quiz2
8 questions
Lesson 3 - Class Structure & SyntaxFor this lesson we looked at class structure and syntax within our Java programs.Quiz3
8 questions
Lesson 4 - Reference VariablesThis lesson is about reference variables and how to use them within our Java programs.Quiz4
7 questions
Lesson 5 - Methods - BasicsWe have used methods throughout the lessons so its now time for a thorough investigation of what we can do with these members by starting with the basics.Quiz5
7 questions
Lesson 6 - Methods - Passing ValuesIn our second lesson on Java methods we investigate the concept of pass-by-value and what this means when we pass values to our methods.Quiz6
6 questions
Lesson 7 - Methods - Overloading & VarargsIn our final lesson on Java methods we look at method overloading and variable arguments.Quiz7
7 questions
Lesson 8 - Instance Variables & ScopeThis lesson is about instance variables, how to use them and their scope.Quiz8
7 questions
Lesson 9 - Final Instance VariablesThis lesson is about final instance variables, how we use them and the rules associated with them.Quiz9
7 questions
Lesson 10 - Constructor BasicsIn this lesson we learn the basics about constructors and how we use them to instantiate objects of our classes.Quiz10
7 questions
Lesson 11 - Overloaded Constructors and thisIn this lesson we learn constructor overloading and how to use the this keyword.Quiz11
9 questions
Lesson 12 - Static OverviewIn the first of three lessons on statics we investigate what the static keyword means and how to use static variables.Quiz12
7 questions
Lesson 13 - Static MethodsIn this lesson we look at static methods and the rules on how to use them within our Java classes.This quiz.
6 questions
Lesson 14 - Java ConstantsIn this lesson we investigate Java constants and how to use static initializer blocks.Quiz14
7 questions
Lesson 15 - Basic EnumerationsIn the first of two lessons on enumerations which were introduced in Java5, we look at the basics.Quiz15
8 questions
Lesson 16 - Advanced EnumerationsIn our final lesson of this section we look at some advanced uses of enumerations.Quiz16
6 questions

Java Objects & Classes Quiz 13

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

Question 1 : What will be output from the following code snippet?

public class StatCalls {
    public static void main (String[] args) {
        int aSquare = squareNumber(5);
        System.out.println(aSquare);
    }
    int squareNumber(int number) {
        int square = number * number;
        return square;
    }
}
- The code snippet will not compile as a non-static method cannot be referenced from a static content.
Question 2 : Static methods run without any instance of a class being involved?
- Static methods DO run without any instance of a class being involved.
Question 3 : What will be output from the following code snippet?

public class StatCalls2 {
    public static void main (String[] args) {
        this.number = 6;
        int aSquare = StatCalls2.squareNumber(this.number);
        System.out.println(aSquare);
    }
    int squareNumber(int number) {
        int square = number * number;
        return square;
    }
}
- The code snippet will not compile as a non-static variable cannot be referenced from a static content.
Question 4 : You cannot access an instance variable from a static method?
- You CAN access an instance variable from a static method by using a local reference from within your static method to access non-static content.
Question 5 : What will be output from the following code snippet?

public class AccessNonStatic {
    int nonStatic = 28;

    public static void main (String[] args) {
        AccessNonStatic ans = new AccessNonStatic();
        System.out.println(ans.nonStatic); // Calling non-static
    }
}
- The code snippet will compile and output 28 as we are using a local reference from within a static method to access non-static content, which is fine.
Question 6 : We can use instantiation from within our static methods?
- We CAN use instantiation from within our static methods.
Quiz Progress Bar Please select an answer

What's Next?

The next quiz we investigate Java constants and how to use static initializer blocks.