0% found this document useful (0 votes)
1 views

10.java

Uploaded by

dhaouadi.eya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

10.java

Uploaded by

dhaouadi.eya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

OOP CONCEPTS:

3.Polymorphism (many forms):

>the ability to perform a single action(method) in different ways.

>it occurs when we have many classes related by inheritance.

•Class "Object":
the class at the very top of inheritance tree.
all Java classes inherit from Object (common ancestor).

>defined in the java.lang package

>Methods of Object Class:

•public final Class getClass() -> returns object of type "Class":


the runtime class of the object.

---------
•public int hashCode() -> returns the hashcode number of the object.

---------
•protected Object clone() throws CloneNotSupportedException
-> creates and returns the exact copy(clone) of "this" object.

---------
•public final void notify() -> wakes up 1 thread waiting on the
object's monitor.

---------
•public final void notifyAll() -> wakes up all threads.

---------
•public final void wait(long timeout) throws InterruptedException
-> current thread wait for specified milliseconds, until another
thread notifies (invokes notify() and notifyAll()).

---------
•public final void wait(long timeout,int nanos) throws InterruptedException
-> current thread wait for specified millisecondsand nanoseconds, until
another thread notifies (invokes notify() and notifyAll()).

---------
•public final void wait() throws InterruptedException
-> current thread wait, until another thread notifies (invokes notify() and
notifyAll()).

---------
•protected void finalize() throws Throwable -> invoked by the garbage
collector before object is being garbage
collected.

---------
•public String toString()
-> returns the string representation of "this" object.

--------------------------------------------------
public String toString()
{
return name+" "+age+" "+employeeID+" "+salary;
}
--------------------------------------------------
-in MAIN method:
System.out.println(employee1);
System.out.println(employee1.toString);

-->Same result: John 35 253 1600

---------
•public boolean equals(Object obj) -> compares given object with "this"
object.
(Object: name of the obj class)
1-----------------------------------------------------
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null || getClass() != obj.getClass())
{
return false;
}

}
-------------------------------------------------------
-->checked object references, classes and if it is null

2-------------------------------------------------------
public boolean equals(Object obj)
{
if (obj instanceof Employee)
{
return employeeID == ((Employee)obj.employeeID);
}
--------------------------------------------------------
--> if the object is an instance of the class, then
compare the unique attribute(ID) of both objects.

-----------------------------------------------------------------------------------
---------
•Final Methods:
>cannot be overridden
>useful for security purposes

--------------------------------------------------------------
public final boolean validatePassword(String name, String pwd)
{
...
}
--------------------------------------------------------------

•Final Classes:
>cannot be extended (don't have subclasses)

--------------------------------------------------------------
public final class CLASSNAME
{
...
}
--------------------------------------------------------------

You might also like