OOPS and Core Java Interview Question and Answers

29. How can we force the garbage collector to run?
  Garbage collector can be run forcibly using "System.gc()" or "Runtime.gc()".
 
Your Name Your Email-ID
Your Answer
30. How can you copy one array in to a different array?
  System.arraycopy(myOldArray, 0, myNewArray, 0, length);
 
Your Name Your Email-ID
Your Answer
31. Distinguish between String class and StringBuffer class in Java in terms of their implementations?
 
  • An object of class String in Java is immutable.
  • That is, once a string object has been created, the characters that comprise that string cannot be changed.
  • Whereas an object of class stringBuffer can be modified after it has been created. String represents fixed- length, immutable character sequences. In contrast, stringBuffer represents growable and writeable character sequences.
 
Your Name Your Email-ID
Your Answer
32. How can we implement polymorphism in Java?
 
  • Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. There are two types of polymorphism.
  • Method polymorphism through overloading Object polymorphism by inheritance/interfaces.
 
Your Name Your Email-ID
Your Answer
12345678910 Page 8 of 10