Java Interview Guide: How to Build Confidence With a Solid Understanding of Core Java Principles pdfdrive com



Yüklə 0,53 Mb.
Pdf görüntüsü
səhifə8/47
tarix06.05.2023
ölçüsü0,53 Mb.
#108601
1   ...   4   5   6   7   8   9   10   11   ...   47
Java Interview Guide

Access Modifiers
Access modifiers determine the visibility of classes, fields, and methods, so that
information can be hidden in order to reduce complexity. The four types
of access modifiers are: Public – Visible to all classes.
Protected
– Visible to subclasses and classes in the same package.

– Visible to classes in the same package.
Private
– Visible to the enclosing class.


Annotations
Annotations can be applied to fields, methods, classes, and packages to embed
metadata alongside code. Annotations alone have no effect on a codebase,
but they can be detected during compile-time or during runtime to provide
additional functionality. For example, the @Override annotation can be used
on methods that override a superclass method, allowing the compiler to prevent
bugs due to invalid method signatures. The @Column(name) annotation can
be used to map fields to database columns, allowing data access objects
to dynamically generate SQL queries at runtime.


Questions
What is the difference between a method declaration and a method signature?
What is a recursive method?
What is the final keyword used for?
What is the static keyword used for?
Why can’t a static method access a nonstatic field?
What are access modifiers used for? What are the different types?
What are annotations used for?


The Object Superclass
Every class in Java is a descendent, directly or indirectly, of the Object class.
The Object class provides several methods that can be optionally extended
in subclasses.


Clone
The clone() method was originally designed to return a copy of an object that
implements the Cloneable interface. A clone can either be a shallow copy,
which shares the same references as the original object, or a deep copy, which
copies the values of the original object into new objects. Unfortunately,
overriding this method correctly is difficult and it provides no benefit over
a copy constructor, which offers more flexibility and a cleaner contract.


Equals
The equals() method compares two objects for equality. The default
implementation relies on the identity operator (==) to determine whether two
objects point to the same address in memory. Subclasses are encouraged
to override this method to test whether two objects contain the same information
rather than the same location in memory. Note that if you override the
equals()
method you must by contract override the hashCode() method
as well.



Yüklə 0,53 Mb.

Dostları ilə paylaş:
1   ...   4   5   6   7   8   9   10   11   ...   47




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin