10:06 am - Tuesday January 22, 2019

Basic Interview Question5

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

49. What is the difference between declaring a variable and defining a variable?

In declaration we just mention the type of the variable and it’s name. We do not initialize it. But defining means declaration + initialization.e.g String s; is just a declaration while String s = new String (“abcd”); Or String s = “abcd”; are both definitions.

50. What is the default value of an object reference declared as an instance variable?

Null unless we define it explicitly.

51.  Does garbage collection guarantee that a program will not run out of memory?

Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

52. Can an unreachable object become reachable again?

An unreachable object may become reachable again. This can happen when the object’s finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable objects.

53.  What modifiers are allowed for methods in an Interface?

Only public and abstract modifiers are allowed for methods in interfaces.

54.  What are some alternatives to inheritance?

Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).

55.  What does it mean that a method or field is “static”?

Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That’s how library methods like System.out.println() work out is a static field in the java.lang.System class.

56.  Is Empty .java file a valid source file?

Yes, an empty .java file is a perfectly valid source file.

57.  Can a .java file contain more than one java classes?

Yes, a .java file contain more than one java classes, provided at the most one of them is a public class.

58.  Is String a primitive data type in Java?

No String is not a primitive data type in Java, even though it is one of the most extensively used object. Strings in Java are instances of String class defined in java.lang package.


Filed in: Z-A Interview Questions

No comments yet.

Leave a Reply