47
18

What does static mean?

I know public means that it can be accessed from outside the class, and private only from inside the class…

 

 

42
 

Static means that it can be accessed without instantiating a class. This is good for constants.

Static methods need to have no effect on the state of the object. They can have local variables in addition to the parameters.'

 

 

 

 

40

public: Public declared items can be accessed everywhere.

protected: Protected limits access to inherited and parent classes (and to the class that defines the item).

private: Private limits visibility only to the class that defines the item.

static: A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope.

final: Final keywords prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.


Beside of PHP:

transient: A transient variable is a variable that may not be serialized.

volatile: A variable that might be concurrently modified by multiple threads should be declared volatile. Variables declared to be volatile won't be optimized by the compiler because their value can change at anytime.

 

 

 

0

Example:

public class Methods_Test1 
{   
    public static void Display(String Name)
    {
        System.out.println("Hello There " + Name);
        System.out.println("I am from Display method");
    }


    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter name");
        String name = sc.next();
        Obj.Display(name);

    }

The public static void Display(String name) method accessible as static method within its own class which can be accessed without creating object of the class where as the same method behaves as public for the outside classes which can be accessed by creating object.

 

 

 

'WEB > PHP' 카테고리의 다른 글

[고도몰 Pro+] SFTP 접속이 안됨과 동시에 문제 해결하기  (0) 2023.05.25
FTP 설정 방법 - 고도몰  (0) 2023.05.18
PHP 실행 지연(delay) 시키기  (0) 2021.11.23
mb_substr  (0) 2021.09.13
PHP Superglobal - $_REQUEST  (0) 2021.08.18

+ Recent posts