Calling Class Methods - AP Computer Science A

  1. What happens if you call a static method with a null reference?
    No error; static method is called on class. Static methods belong to class, not instance.
  2. How do you call a static method from a different package?
    Import the class, then call ClassName.methodName();. Import statement provides access to external classes.
  3. Identify the error: public void static print() {}
    Incorrect order; should be public static void print() {}. Modifiers must follow specific order: access, static, return.
  4. What type of methods can be called without creating an object?
    Static methods. Class methods don't require object instantiation.
  5. Identify the error: static void display() { this.show(); }
    Cannot use 'this' in a static method. 'this' refers to instance, not available in static context.
  6. Can a static method call a non-static method directly?
    No, it cannot. Static context cannot access instance methods directly.
  7. What keyword is used to define a class method?
    static. Makes method belong to class rather than instances.
  8. How do you call a static method from a class?
    ClassName.methodName();. Uses dot notation with class name, no object needed.
  9. Can static methods be overridden?
    No, they can be hidden but not overridden. Static methods are resolved at compile-time, not runtime.
  10. What is the result of calling a non-static method using the class name?
    Compilation error. Non-static methods require an instance to be called.
  11. How do you call the main method of another class?
    OtherClass.main(args);. Main method is static, so use class name to call.
  12. Can a static method be overloaded?
    Yes, it can. Multiple static methods can have same name, different parameters.
  13. State the syntax for calling a static method in Java.
    ClassName.methodName();. Standard format for accessing class-level methods.
  14. Which method is called automatically when a Java program starts?
    main method. Entry point for Java program execution.
  15. Can a static method have a return type?
    Yes, it can. Static methods can return values like any method.
  16. Identify the error: static int calculate() return 0;
    Missing curly braces. Method body requires braces around statements.
  17. What is the signature of the main method in Java?
    public static void main(String[] args). Required format for Java application entry point.
  18. Can a static method be abstract?
    No, it cannot. Abstract requires overriding, but static prevents inheritance.
  19. Can a static method call another static method?
    Yes, it can. Static methods can invoke other static methods directly.
  20. What are the parameters of the main method in Java?
    String[] args. Command-line arguments passed to program.
  21. What is the scope of a static method?
    Class level. Belongs to the class, shared across all instances.
  22. Can static methods access instance variables directly?
    No, they cannot. Instance variables belong to objects, not the class.
  23. Can a static method access a static variable?
    Yes, it can. Static methods can access other static members.

Study these flashcards