


















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















































1
2
(^) AboutAbout OOP :OOP :
(^) Procedure Oriented Vs. Object Oriented
(^) OOP ConceptsOOP Concepts
(^) Objects & Classes
Problem solving in OOP methodology
(^) Implementation issues in JavaImplementation issues in Java
(^) Java Features for OOPSJava Features for OOPS
(^) The final keyword appears before the class keyword when declaring a final class. For example:
public final class Hourly extends Employee
{
//Class definition...
}
(^) A compiler error is generated if you try to write a class that subclasses Hourly. The following class declaration will not compile:
public class PartTime extends Hourly //error!
{
//Class definition...
}
4
(^) When a child class overrides a method in the parent class,
the overridden method is essentially hidden.
(^) The only way the parent method can be invoked is if the
child method explicitly invokes it. If you write a method with important behavior that you do not want a child class to override, you can declare the method final.final.
(^) A final method cannot be overridden by a child class.
(^) The getClass(), wait(), and notify() methods of the Object
class are declared final. Their implementations are essential for the proper behavior of an object, and these methods cannot be overridden by any class.
5
(^) When an object is instantiated, the sequence of events occurs:
class.
another constructor in the child class. Eventually, a constructor in the child class will be invoked that does not have this() as its first line of code.
a parent class constructor must be invoked.
This is done using the super keyword. If a constructor does
not explicitly make a call using super, the compiler will call super() with empty parentheses, thereby invoking the no argument parent class constructor.
7
8
(^) Notice that the BigScreenTV constructor explicitly invokes the no argument constructor in Television using the statement:
super();
(^) The following ConstructorDemo program instantiates a BigScreenTV object.
(^) Try to determine the output,
public class ConstructorDemo
{
public static void main(String [] args)
{
System.out.println(“Constructing a big screen TV”);
BigScreenTV tv = new BigScreenTV();
System.out.println(“Done constructing TV”);
}
}
10
11
(^) Within main() of ConstructorDemo, we instantiate a
BigScreenTV object
(^) This statement invokes the noargument constructor
in the BigScreenTV class.
(^) The constructor in BigScreenTV invokes the no
argument constructor in Television.
(^) The noargument Television constructor invokes the
other Television constructor, which does not have a this() or super() statement.
(^) Therefore, the compiler added super(), causing the no
argument constructor in Object to be invoked.
Instantiation
(^) Objects & Classes in JavaObjects & Classes in Java
Lab. Exercises (^) Objective : Writing a Class in Java
(^) Instantiating an Object : Understanding the Methods, references etc. (^) Inheritance: Characteristics & Implementation (^) Method Overloading & Overriding
(^) Java Features for OOM: Organizing ClassesJava Features for OOM: Organizing Classes
How to Add class to a package
Java Platform & OOM
Packages in Java Platform
13
(^) As we have seen that we create Java Class for
problem solving in OOM.
(^) As for each and every component , there is a Class
written, consequently we are having large number of Classes.
(^) We are using various OOM characteristics like
Inheritance etc. for making use of Class Characteristics.
(^) For the efficient handling of the Classes, for re
usability of some classes( which are required very often in many problem solving) and also to use many inherent Core / Foundation Classes, we need to Organize these Classes with useful mechanism.
14
Every class belongs to a package. Packages have two basic purposes:
Packages provide a mechanism for organizing classes.
Packages provide a namespace for the classes within the package.
(^) When developing a Java program, you put classes that go together in the same package.
(^) Java packages can be stored in compressed files called JAR
files, allowing classes to download faster as a group rather than one at a time.
(^) Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality.
(^) Classes in the same package can access each other's packageaccess members.
16
(^) A class is added to a package using the package keyword.package
The package statement must be the first statement in your source code
(^) For example, suppose we wanted to create a package named
payroll for the Employee, Salary, and Hourly classes used in our program to pay employees.
(^) The package declaration must appear first in the statements
in the Employee source code.
(^) The class will not compile if an attempt is made to put any
statement besides comments before the package declaration.
17
(^) If we want Salary and Hourly in the payroll package also, we simply add the package statement to their class definition as well. For example, the Salary class would look similar to:
package payroll; package payroll
public class Salary extends Employee
{
//Salary definition...
}
and the Hourly class would look similar to:
package payroll;package payroll
public class Hourly extends Employee
{
//Hourly definition...
}
19
(^) Packages create a namespace for all classes. If a class is in a
package , the name of the package becomes a part of the name of the class. The package name is prefixed to the name of your class, separated by the dot operator.
(^) For example, the Employee class is declared in the payroll
package. The Employee class is now referred to:
payroll.Employee
(^) The Employee class can no longer be referred to as simply
Employee. The package name payroll must be used by any other class outside of the payroll package that wants to use the Employee class. Similarly, the Salary and Hourly classes become:
(^) payroll.Salary
(^) payroll.Hourly
20