corejava10

46. How does the statement System.out.println() work?
Inside the System class is the declaration of ‘out’ that looks like: ‘public static final PrintStream out’, and inside the Prinstream class is a declaration of ‘println()’ that has a method signature that looks like: ‘public void println()’.
Here is what it actually looks like:
//the System class belongs to java.lang package
class System {
  public static final PrintStream out;
  //...
}

//the Prinstream class belongs to java.io package
class PrintStream{
public void println();
//...
}

47. What is private constructor?Why is it used?
The constructor is known as private constructor when a private modifier is applied to it.It says that only the native class is allowed to create an instance of the class, and no other caller is permitted to do so. There are two possible reasons to use a private constructor – the first is that you don’t want any objects of your class to be created at all, and the second is that you only want objects to be created internally – as in only created in your class.
Eg.for Singleton design pattern,for static classes etc.

48. Is the JVM (Java Virtual Machine) platform independent?
JVM depends on the operating system so it is not platform independent.

49. Can finalize method be overloaded?
Yes but only the following version is called by garbage collector:
    protected void finalize() throws Throwable { };

50. Does the finalize method in subclass invoke finalize method in super class?
Finalize is not implicitly chained. A finalize method in sub-class  should call finalize in super class explicitly as its last action for  proper functioning . Compilers does not enforce this check.

No comments:

Post a Comment