Correct Answer: new ClassName(); This expression creates object in heap area and returns that obj address Here JVM creates object but JVM does not returns object original address JVM returns duplicate address, duplicate address is also called as hashcode
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'
5. 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(); } }
6. What is the differnce among public, protected and package access data?
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
7. In a class if private data member is declared then how to set data to that private data member?
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