21)What's the difference between the == operator and the equals() method? What test does
Object.equals() use, and why?
The == operator would be used, in an object sense, to see if the two objects were
actually the same object. This operator looks at the actually memory address to see if it
actually the same object. The equals() method is used to compare the values of the
object respectively. This is used in a higher level to see if the object values are equal.
Of course the the equals() method would be overloaded in a meaningful way for
whatever object that you were working with.
22)why do you create interfaces, and when MUST you use one.
You would create interfaces when you have two or more functionalities talking to each other. Doing it this
way help you in creating a protocol between the parties involved.
23)What is the difference between instanceof and isInstance?
instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class
exception.
isInstance()--Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a
ClassCastException. It returns false otherwise.
24)How many methods do u implement if implement the Serializable Interface?
The Serializable interface is just a "marker" interface, with no methods of its own to implement.
Are there any other 'marker' interfaces?
java.rmi.Remote
java.util.EventListener
25)Name four methods every Java class will have.
public String toString();
public Object clone();
public boolean equals();
public int hashCode();
26)What does the "abstract" keyword mean in front of a method? A class?
Abstract keyword declares either a method or a class. If a method has a abstract keyword in front of it,it is called abstract method.Abstract method hs no body.It has only arguments and return type.
Abstract methods act as placeholder methods that are implemented in the subclasses.Abstract classes can't be instantiated.If a class is declared as abstract,no objects of that class can be created.If a class contains any abstract method it must be declared as abstract.
27)Does Java have destructors?
No garbage collector does the job working in the background
28)Are constructors inherited? Can a subclass call the parent's class constructor? When?
You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it's superclasses. One of the main reasons is because you probably don't want to overide the superclasses constructor, which would be possible if they were inherited. By giving the developer the ability to override a superclasses constructor you would erode the encapsulation abilities of the language.
29)What does the "final" keyword mean in front of a variable? A method? A class?
FINAL for a variable : value is constant
FINAL for a method : cannot be overridden
FINAL for a class : cannot be derived
30)Access specifiers: "public", "protected", "private", nothing?
Public – any other class from any package can instantiate and execute the classes and methods
Protected – only subclasses and classes inside of the package can access the classes and methods
Private – the original class is the only class allowed to executed the methods.
No comments:
Post a Comment