What is the difference between an instance method and a class method?
Ans : An instance method has a this instance reference, whereas a class method does not. An instance method always works hand in hand with a class instance. An instance method must be invoked on a specific class instance, and it has special access to the data in that instance. For example: String s1 = “abcde”; // one String instance String s2 = “fgh”; // another String instance int i1 = s1.length(); // i1 = 5 int i2 = s2.length(); // i2 = 3 The length method returns the number of characters in its target object (s1 or s2 in this example), just as if that target were an argument to a length function (cf. strlen(aString) in C). When defining an instance method, you can use the this keyword to refer to the target instance. Class methods have no target instance and thus no implicit this reference. Class methods can always be used, even if you have no instance of the class on hand. Class methods, like class variables, are declared with the static keyword. For example, the currentThread meth