Вы находитесь на странице: 1из 2

static - keyword, it is for * like static in C & C++.

* we can call attributes & methods of a class without creating objects. Font.BOLD - with classname Font f; f.BOLD - with object Font f = new Font("Times New Roman",Font.BOLD,12); Integer.parseInt(aa[0]); * static data members not duplicate for each object, act like a global variables. for declaring global variables in C & C++ we have concept of pre processor or declare variable out side the main method. #include<stdio.h> #define MAX 5 - global var int x = 100; - global var void main() { int a = 10; - local var } but declaring global variables in java we have only concept of static declaration. * static data members can be access with classname, object name & direct also. but non static members only access with objects. Font.BOLD - with classname Font f; f.BOLD - with object but if BOLD is an non static variables of Font class then we can access with object only. Font f; f.BOLD - with object * static can be variables, methods, objects, class & can be block also. * any concept use with classname that is static. classname.varname - static variable ex- Font.BOLD classname.methodName() - static method ex- Integer.parseInt() classname.objname - static object ex- System.out static {} - static block.

Q- how to display welcome msg in java without using p s v m? Ans - yes can display/design with the help of static block. all static blocks call by the JVM before calling any method - 1st calling. like pre processor in C & C++. class Hello { static { System.out.println("Sushil Khush Hua"); } } it display exception also - NoSuchMethodError - main. bcos there is no p s v m. but if we have System.exit(0); in static block then that is not. System.exit(0); like exit(0); in C & C++ main. exit points break - exit from the loop. return - exit from the function. exit(0); - exit from the program Error - compile time error Exception - runtime errors. Buggs - at the user end. Debugging - buggs removing process.

Вам также может понравиться