Method contains name, parameters, return type and executable body But block does not contains name, parameters, return typeIt contains only executable body Methods are executed by method call statements Blocks are executed automatically with class loading and with object creation
Technology problems
Search Results
1. In a class if private data member is declared then how to get value of that data member?
Correct Answer: If we are not using packages and if we are not using inheritance then there is no difference among public, protected and package access data
4. When this. non-static datamember is compulsory inside non-static method
Correct Answer: Whenever there is local- variable/parameter inside the method with same name as data member Ex: Class Sample { int a; void show() { int a=5; systemoutprintln(a); // 5 systemoutprintln(thisa);//23 } } class MainApp { Public static void main(String[] args) { Sample s = new Sample(); sa = 23; sshow(); } }
Correct Answer: This is a keyword and used as reference to Current object address in java It means by using which object the method is called that object hashcode is stored inside the 'this'
Correct Answer: Constructor is not a special method Constructor is block of code that is executed automatically whenever object of the class is created
Correct Answer: new ClassName( arg1, arg2, argN); Ex: Class sample { Sample(int a) { Systemoutprintln("arg con a =" +a); } } class Demo { Public static void main( String[] args) { Sample s1= new Sample(23); Sample s2= new Sample(45); } }
8. What is different among String, StringBuffer, StringBuilder?
Correct Answer: String class objects are immutable objects and they represents strings( sequence of characters) StringBuffer class objects are mutable objects representing strings and they are Thread safe StringBuild class objects are also mutable objects representing strings and they are not Thread safe
Correct Answer: Wrapping is also called as packing or boxing Storing the data inside the object as private data which can accessed outside the class only by using methods
Correct Answer: Unwrapping is also called as unpacking or unboxing Getting the private data stored in the object by using methods is called unpacking or unwrapping