Answers for "static vs non static java"

0

Completely uninstall apache2

$sudo service apache2 stop

$ sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
$ sudo apt-get autoremove

$ whereis apache2
Posted by: Guest on July-16-2021
0

can you run non static method on main

//You simply need to create an instance of the Object you created
public Class Obj{
	public void nonStaticMethod(){
	//execute code
	}
	public static void main(string args[]){
		Obj obj = new Obj();
	    obj.nonStaticMethod
	}
}
Posted by: Guest on June-01-2020
1

static vs non static java

// Static vs Object Called
// Static Methods don't require you to call a constructor

// Initialize statically
public class MyClass {

  private static int myInt;

  static {
      myInt = 1;
  }

  public static int getInt() {
      return myInt;
  }
}

// Then call it
System.out.println(MyClass.getInt());

// VS Constructor

public class MyClass {
 
  private int myInt;
  
  public MyClass() {
    myInt = 1;
  }
  
  public int getInt() {
	return this.myInt;
  }
}
// Then call it
MyClass myObj = new MyClass();
System.out.println(myObj.getInt());
Posted by: Guest on July-10-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language