|1) Enlist the difference between Procedural Programming
and Objet Oriented Programming Language.
2) What is class and Object in JAVA?
Each class is a collection of data and the function that manipulate the data. The data components of the class are called data fields and the function components of the class are called member functions or module. The class that contains main function is called main class.
Object is an instance of a class. The objects represent real world entity. The objects are used to provide a practical basis for the real world. Objects are used to understand the real world. The object can be declared by specifying the name of the class. For example for the class rectangle we can create the objects as follows:- rectangle r1,r2,r3;
The declaration of objects is similar to declaration of variables. The operator new is used to create an object.
3) What do you mean by constructor? Explain with example.
The constructor is a specialized method used for initializing the objects. Note that the name of the constructor and the name of the class must be the same. The constructor invoked whenever an object of its associated class is created. It is called constructor because it creates the values for the data fields of the class.
public class rectangle
4) What is finalizer? Explain.
Java has a facility of automatic garbage collection. Hence even though we allocate the memory and then forget to deallocate it then the objects are no longer is used get freed. Inside the finalize() method you will specify those actions that must be performed before an object is destroyed. The garbage collector runs periodically checking for objects that are no longer referenced by any running state or indirectly though other referenced objects. To add finalizer to a class simply define the finalize method. The syntax to finalize() the code is
5) What do you mean by package-ptivate or package-access?
Access modifiers control access to data fields, methods,
and classes. There are three modifiers used in java-public,
public allows classes, methods and data fields accessible from any class.
private allows classes, methods and data fields accessible only from within the own class.
If public or private is not used then by default the classes, methods and data fields are accessible by any class in the same package. This is called package private or package-access. A package is essentially grouping of classes.
6) How to pass and return the objects to and from the method? How to pass objects to the method?
The object can be passed to a method as an argument. Using
dot operator the object’s value can be accessed. Such a method can be represented
syntactically as Data_type name_of_method(object_name)
7) How to Return an object from a method?
We can return an object from a method. The data type such method is a class type.
public class ObjRefDemo
Ask It in The Java Forum
Return to : Java Programming Hints and Tips
All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.