Computer Science, asked by Anonymous, 1 year ago

Write a program in java to show the difference between static method and instance method

Answers

Answered by sushiladevi4418
17

Answer:

Program in java for the static and instance method.

Explanation:

Program for Static Method:-

public class TestClass {

 public static void main(String[] args) {

   display(); //there is no object create here because display is a static method

 }

 public static void display(){

   System.out.println("Call from static method");

 }

}

Program for Instance Method:-

public class TestClass {

 public static void main(String[] args) {

   TestClass tc = new TestClass();

   tc.display(); //object create here because display is a instance method

 }

 public void display(){

   System.out.println("Call from instance method");

 }

}

Similar questions