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
2. 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'
4. Why static method can not call non static method of the same class?
Correct Answer: 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
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); } }
10. 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