Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Yes, main method can be overloaded. Overloaded main method has to be called
from inside the "public static voidmain(String args[])" as this is the entry point when
the class is launched by the JVM.
So when you call the constructor using a new keyword you get an object. Though it
doesnt explicitly return something but instead it creates or constructs something
which you can use as an instance of a class. yes, it is the current class instance. (We
cannot use return type yet it returns a value)
Yes You can compile and execute without main method By using static block. But
after static block executed (printed) you will get an error saying no main
methodfound. And Latest INFO --> YOU cant Do this with JAVA 7 version. IT will not
execute.
6. this can be used to return the current class instance from the method.
In C++ there is a possibility to get into this trap though it provides alternates to solve
this. In java this can never occur as there is no multiple inheritance. Here even if two
interfaces are going to have same method, the implementing class will have only one
method and that too will be done by the implementer.
No,Static methods can't be overriden as it is part of a class rather than an object. But
one can overload static method.
Covariant return, means that when one overrides a method, the return type of the
overriding method is allowed to be a subtype of the overridden method's return type.
To clarify this with an example, a common case is Object.clone() - which is declared
to return a type of Object .
A blank final is a final variable whose declaration lacks an initializer. You then must
assign that blank final variable in a constructor. The final property of class must have
a value assigned before object is created. ... This is how you make immutable objects
and it is used in the builder pattern.
It is used to convey to the JVM that the class implementing an interface of this
category will have some special behavior. Hence, an empty interface in java is called
a marker interface. Marker interface is also called tag interface by some java
gurus.
upcasting means casting the object to a supertype, while downcasting means casting
to a subtype. Injava, upcasting is not necessary as it's done automatically. And it's
usually referred as implicit casting. ... Actually at runtime it could be different
andjava will throw a ClassCastException , would that happen.
o What is the purpose of private constructor?
A singleton is a design pattern that allows only one instance of your class to be
created, and this can be accomplished by using a private constructor. Yes and it is
used to prevent instantiation and subsequently overriding. This is most often used
in singleton classes.
The object cloning is a way to create exact copy of an object. For this
purpose,clone() method of Object class is used to clone an object. The
java.lang.Cloneable interface must be implemented by the class whose object
clone we want to create.