+ 4
Help about static keyword in java
Why we write static before the function ? what it mean ? And why it gives error if we not write static ?
6 Réponses
+ 4
Many say java is not a "pure" object oriented language because java supports primitive data types (boolean, int float etc). For a language to be pure object oriented there should be only objects and classes. However there is no actual definition of "pure" or 100% object oriented language.
But that should not effect you in any way. Having primitive data types is a good thing.
+ 8
Both variables and methods can be static. By declaring them static we do not need to create objects of the class but we can directly use them by the calling the class eg
public class MyClass{
public static String name = "Ahmed";
public static void myMethod(){
System.out.println("Hello");
}
}
public class B{
public static void main(String[] args){
MyClass.myMethod();
System.out.println(MyClass.name);
}
}
Here i used static variable and method of one class in another class without creating its object.
You are getting error because static methods cannot access non-static methods. Since main() method is always static so if you want to access your method from it you have to declare it static.
+ 6
static mean that you don't need object to call some method, method belong to it's class
+ 5
No java is an object oriented language. Objects are its integral part.
+ 1
is it true that there is nothing like object in java ?
+ 1
and why we say java is nearly 100% object oriented language why not total 100%