Question: QUESTION 5 (a) What are static methods? Explain the difference between things that belong to the class itself and those that belong to an instance

QUESTION 5 (a) What are static methods? Explain the difference between things that belong to the class itself and those that belong to an instance of the class. (2 marks) (b) What is a Singleton class? How is it implemented in java? (4 marks) (c) When you try to compile the class Q5C below the compiler will generate the following error message: non-static variable num2 cannot be referenced from a static context. Explain why it generates this message. Rewrite it so that it does not give a compile error. class Q5C{ private static int num1 = 0; private int num2; public Q5C(int n){num2 = n;} public static void modNum2 (int n) {num2 = n;} } (4 marks) Total (10 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
