Site icon DataFlair

Quiz on Java Static Methods

quiz on java static methods

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Static methods are a cornerstone of object-oriented programming in Java. Unlike regular methods tied to specific objects, static methods belong to the class itself. This unique characteristic offers a multitude of benefits. Static methods promote code organization by allowing you to group helper functions or utility methods directly within the class definition, keeping your code clean and modular.

Furthermore, static methods optimize memory usage. Since they are not tied to individual objects, they are loaded into memory only once when the class is first referenced, improving efficiency. This blog post delves into the world of static methods with an engaging quiz!

The quiz will assess your understanding of core concepts like creating and calling static methods, their role in memory management, and best practices for their use. Whether you’re a seasoned Java developer or just starting out, this quiz serves as a valuable tool to solidify your grasp of static methods and propel you on your programming journey! So, dive in, challenge yourself, and embrace the power of static methods in Java!

Time limit: 0

Quiz Summary

0 of 15 Questions completed

Questions:

Information

You have already completed the quiz before. Hence you can not start it again.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    Which of the following is the correct way to invoke a static method ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    class Method {

    static void square(int a)

    {

    return(a*a);

    }

    public static void main ( String args [ ] )

    {

    System.out.println(square(5));

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    class Function {

        void display()

    {

    system.out.println(“Non-static method”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Function.display();

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following cannot be done using the static methods in java?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    class One {

    static addition(int a , int b)

    {

    return a+b;

    }

    static subtraction(int a , int b)

    {

    return a-b;

    }

    public static void main ( String args [ ] )

    {

    System.out.println(addition(2,3)+”,”+subtraction(3,2));

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

     class A {

    static method1()

    {

    System.out.println(“Static method”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    method1();

    }

    }

    What is the error in the program ?

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which of the following keywords raise an error in static methods ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

     class Text {

    String name = “ ”;

    static void display(string a)

    {

    name = a;

    System.out.println(name);

    }

    public void print(String b)

    {

    name = b;

    System.out.println(name);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Text.display(“DataFlair”);

    Text t = new Text();

    t.print(“Webservices”);

    }

    }

    What should be the output of the program ?

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

     class Main {

    public static void main ( String args [ ] )

    {

    static void method(int a , int b , int c )

    {

    return a*b*c*;

    }

    method(10.9.8);

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of the following is the syntax for invoking static methods ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class Objects {

    Static void display()

    {

    System.out.println(“static class method”);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Objects obj = new Objects();

    obj.display();

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

     class Method {

        int b;

    Method(static int a)

    {

    b = this.a;

    system.out.println(b);

    }

    public static void main ( String args [ ] )

    {

    Method m = new Method(10);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

     Which of the following concepts are used in static methods ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

    class StaticMethods {

    public static void main  ( String args [ ] )

    {

    static int b = 10;

    static void value( b)

    {

    Static int a = b*b;

    }

    System.out.println(a);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

     class Sample {

    static void calculate( int x )

    {

    System.out.println(3.14*x*x);

    }

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Sample.calculate(4);

    }

    }

    What will be the output of the program ?

    Correct
    Incorrect

Summary:

Congratulations on completing the Java Static Methods Quiz! By attempting this quiz, you’ve actively engaged with core concepts like invoking static methods using the class name, understanding their benefits for code reusability and memory management, and recognizing scenarios where static methods are not applicable.

Remember, effective learning is an ongoing process. Explore additional resources beyond the quiz, such as online tutorials and practice problems. Consider participating in online communities to connect with other Java developers and broaden your knowledge. By continuously learning and applying your understanding, you’ll become a confident and proficient Java programmer.

Exit mobile version