Monday, August 30, 2010

powerbuilder interview question _ part 8

POLYMORPHISM

1. What is polymorphism ?
Polymorphism is functions with the same name that can do different things for different objects and give different results . For example, 1 + 1 = 2 mathematics plus
“John” + “Smith” Concatenation plus
Polymorphism is a feature of an object-oriented language which defines same methods for different objects. Example: Let’s say, you are going to have several windows in your program, all of them with DataWindows and Retrieve buttons. We want to be generic and put code for the retrieve event in the function of the ancestor window. But some of these DataWindows are with external data source and have to be handled differently than the rest. Our solution is to create a generic function for retrieve in the window-ancestor and for the window with special handling create their own functions with the same name as in the ancestor. The function in a descendant will overload the ancestor’s function. We can define a Print function for a different kinds of objects. Each has its own definition of what print does.

2. How do you understand using Overloading functions in Polymorphism?
Overloading is functions with the same names with different parameters that can be used in the same object. Away in which polymorphism works in PowerBuilder. Means that when several functions the same name exist in ancestors and descendants call to another (with different function body) will overload (change) function’s body in the memory.

3. What is overloading?
When the function of the object has the same name but different arguments.

4. What is polymorphism?
Polymorphism is when functions have the same name but behavior varies with the type of the object to which it is applied.

5. Give examples of polymorphic functions in PowerBuilder.
For example, 1 +1 = 2 mathematics plus
“John” + “Smith” Concatenation plus
Another example: When you implement polymorphism, it’s common to create an ancestor object that has a method in it but no code. E.g., suppose, that you have a custom class called u_Invoice and one called U-check. They are both descendants of the custom class called u_Document. U_Document has a Print method but it has no code in it. Both u_invoice and u_Check also have a Print method, each with different code. Why create this structure? Because then an application that uses your objects can refer to any document using variables of type u_Document. And when they want to print a document, they can just call the Print method.
Uo_document doc

//NextDocument() may return a u_Invoice or u_Check document
doc = NextDocument()
doc.Print()
This is called dynamic binding. The specific function you are calling isn’t actually resolved until runtime. It just depends on whether the variable doc is holding a u_Invoice or u_Check object.

6. What is polymorphism?
Polymorphism is an object-oriented feature. Different object classes can have functions with the same name which can be used more than once to do different things for different objects. There are situations in which you want to send the same kind of message to different kinds of objects and have each object respond to that message in its own unique way.


1. What is Regenerate option in the Library painter? When is it most useful?
It compiles all codes of an object(s). Regeneration is important during the development of our PB application. Regeneration is useful:
n when we have an error message with no reason for it;
n When we upgrade to a new version of PB, the new version should regenerate all its source code to update it;
n When we make a change to an ancestor window that has many descendants, the changes can be immediately rippled throughout all child window through regeneration.
Regenerating could be called “recompiling”. When you regenerate an entry, PowerBuilder recompiles the source form stored in the library and replaces the existing compiled form with the recompiled form.

2. You are working with inherited windows, and your application does not work or produces ambiguous errors. You are tracing the program though the DEBUGGER, and still - nothing. What can you do next? REGENERATE



SCRIPT

1. How is a script associated with an object ?
When an event occurs, PowerBuilder executes the script for that event.

2. With which objects can a script be associated ? Any.

3. Code the broad outlines of the code necessary to check the value in the integer variable Count against the following ranges of values :
n less than or equal to zero(0)
n equal to 1, 2, or 3
n between 4 and 10 (including 4 and 10)
n over 10.

4. What is a script ?
A script defines the processing that take place when an event occurs for an object or control. When an event occurs, PowerBuilder executes the script for that event. Types of statements in a script are : variable declaration
calls to function
assignment statement
flow of control statement (IF and CHOOSE statements)
embedded SQL statement.

5. Under what circumstances do you need to declare multiple instances of a window class?

6. Assume that when the instance w_cust_maint1 of the window w_cust_maint is displayed, you want its title to read “Referenceable Customer”. Given the following declaration, code the statements to display the window appropriately.
w_cust_maint w_cust_maint1
w_cust_maint1.Title = “Referenceable Customer”

6. What is a focus ?
A focus identifies where on the Window the next action will take place.

7. How do you pass an array as an argument?
To pass an array we should define it as an argument in the window function with brackets. In a script we have to assign an array to a veritable in order to use it.

8. What is an array?
An array is an indexed massive of variables of the same Data Type.
EX. Prise[ ] or Prise[50]
9. Why are static arrays preferable over dynamic arrays?
Static arrays tell us how many elements an array will have by specifying number in brackets. Static arrays are faster.
Dynamic arrays grow dynamically what is more convenient .
Because the memory needed for a static array is located immediately on creation, so there is no reason to reallocate and copy anything and also because boundaries of the array are known when the array is accessed, so there is no processing overhead while checking the validity of the array subscript.

10. What is Array Data type?
Array is a massive of variables of the same Data Type

11. You need to process an array in a loop. Which function should you use if you don’t know array’s size (i.e., number of array elements)?
UPPERBOUND(Array)
int i
FOR i =1 TO UPPERBOUND(Array)
statementblock
NEXT

12. What is enumerated data type? How is it represented and what is its purpose ?
Some functions which were written in some other languages and build into PowerBuilder and PowerBuilder recognises them by the exclamation point at the end.

13. Can you always use CHOOSE…..CASE instead of IF-THEN-ELSE ?
Yes. We can. CHOOSE…..CASE More readable

14. What is the difference between DO… WHILE and DO… UNTIL clauses?
DO… WHILE will perform an action only while the condition is TRUE:
int A = 1, B = 1
DO WHILE condition DO WHILE A <= 15
statementblock BEEP(A)
LOOP A = (A + 1) * B
LOOP
DO… UNTIL will perform an action only until the condition is TRUE:
DO UNTIL condition int A = 1, B = 1
statementblock DO UNTIL A > 15
LOOP BEEP(A)
A = (A + 1) * B
LOOP

15. What is the difference between DO WHILE ….LOOP and DO….LOOP WHILE ?
DO WHILE ….LOOP performs an action only while the condition is TRUE:
DO WHILE condition
statementblock
LOOP
DO….LOOP WHILE performs an action at least once and repeat while the condition is TRUE
DO
statementblock
LOOP WHILE condition

16. What do you use to exit the loop before the condition in the loop is met?
What are the 2 choices?
We use EXIT inside the loop if we want to terminate the loop. EXIT jumps to the first
statement after the loop. Continue skips the rest of the statement inside the loop and returns to the beginning of loop to start the next iteration.

17. What is ANY Data Type ? How is it used?
Any is a chameleon data type — it takes the data type of the value assigned to it.

18. What is a BLOB data type?
BLOB is Unbound data type that stands for binary large object. Usually used to hold pictures, window’s wave sound file or very large text files.
19. How would you display a toolbar on a left side of screen, floating?
Syntax:
window_name .ToolbarAlignament = AlignLeft! (AlignAtTop!,
.... AlignRight!,
.... AlignAtBottom!
.... Floating!)
enumerated datatype

20. How do you put the time in the status bar?
On the open event of a window call Timer(1). On the timer event Time = Now( )
SetMicroHelp(Time)

21. Can Script#1 share a local variable declared in Script#2?
No, it cannot. Local variables are accessible only in the script in which they are declared.

22. What data types do you know?
There are following data types in PowerBuilder :
1. Standard (string,…..)
2. Enumerated data types its a some functions which were made in other languages and pb recognise it by exclamation point at the end
3. Array is a massive of variables of the same Data Type
4. Structure is a collection of one or more related variables of different or the same data types grouped under one name.


23. Where would you put a code to make sure that everything has been saved on the window in case if a user is closing the window?
I would write this code on CloseQuery event of the window. A CloseQuery event occurs every time when the window is to about to be closed. At this moment PowerBuilder checks the value of the attribute. If after performing some processing we don’t want to allow a user to close the window, set Return 1. When we close a window, PowerBuilder triggers the CloseQuery event and inspects the value of Message.ReturnValue. If the Message Return Value 1, the window cannot be closed. Note: Closing any window causes PowerBuilder to close all Child and Pop-up windows that is opened, and closing an MDI frame window causes PowerBuilder to close all sheet windows within it. Any window thus being closed can set Message.ReturnValue to cancel the close operation.

24. Where can external functions be declared?
External functions can be declared in the Application Object, User Object or Window Object. To declare an external functions, select External Functions on the Declare Menu of the current object painter or the PowerScript Painter.

25. What is the maximum number of characters that you can enter into a control?
The maximum size is a little bit more then 32KB


26. What can you do if you want to leave the PowerScript Painter but the script won’t compile?
I’ll put comments(//) on my code. When we are leaving the PowerScript Painter, it automatically compiles our script. We can have a script containing the errors, To save the script without correcting the errors, comment out any lines in errors.

27. What statement evaluates one variable?
Statement Choose Case evaluates one variable.

28. What should be done to make sure that several RadioButtons understand that they belong to the same group (the user can select only one button in the group)?
By using GroupBox control. If the GroupBox contains RadioButtons, the user can select only one RadioButton in the GroupBox at a time.

29. How to update a ListBox without using a DataWindows?
AddItem( )

30. How to pass control as parameter(for ex. DataWindow)?
Specify as an argument in a function a chosen type of this control

31. How many Windows can be in the application?(maximum)
No more then 60 but we have more then 100.

32. Could you invoke DOS editor from PowerBuilder?
Yes pressing Shift-F6 anywhere.
33. How could you invoke help about specific function or reserved word from Power Script painter?
To highlight this function or reserved word and press shift-F1

34. How do we specify processing that takes place in our application?
By writing a script for different events that occurs. PB applications are event-driven.

35. How do you refer to the attribute inside the scripts?
Using syntax calling dot notation:.

36. How can you use enumerated data types?
As an arguments in functions or to specify the attributes of an object or control.

37. What is the array?
An array is an indexed collection of elements of a single data type. Could be fixed or variable size. Fixed-size arrays could be multidimentional.

38. What kind s of iteration(repeated) statements do you know?
For . . .NEXT uses to execute statementblock a specified number of times;
4 formats of DO. . LOOP
DO UNTIL . . . LOOP executes statementblock until condition is TRUE. If condition is TRUE in the first statement statementblock does not execute.
DO WHILE . . . LOOP executes statementblock while condition is true. If condition is FALSE on the first evaluation statementblock does not execute.
DO. . . LOOP UNTIL The same as DO. . . UNTIL LOOP, but statement always executes at least once.
DO. . . LOOP WHILE the same as DO WHILE . . LOOP, but statementblock always executes at least once.

39. What will be the outcome of the following code:
int I = 5
string name = “fox”
If int I = 5 then
if name = “rabbit” then
if I < 10 then
MessageBox(“Status”, “one”)
else
MessageBox(“Status”, “two”)
end if
else
if I <10 then
MessageBox(“Status”, “three”)
elseif I = 5 then
MessageBox(“Status”, “four”)
else
MessageBox(“Status”, “five”)
end if
MessageBox(“Status”, “five”)
end if
elseif I > = 5 then
MessageBox(“Status”, “six”)
end if
MessageBox(“Status”, “three”) and MessageBox(“Status”, “five”)

40. What’s wrong with the logic in the following code:
if years_of_service > 10 then
vacation = 4
bonus_factor = 1.5
elseif years_of_service > 6 and years_of_service < 10 then
vacation = 3
bonus_factor = 1.2
else
vacation = 2
bonus_factor = 1.0
end if
There is nothing said about years_of_service = 10

41. Can we prevent window from closing?
On the close query event we have to write script:
IF MessageBox("Closing window", "Are you sure?", Question!, YesNo!) = 2 THEN
RETURN 1
ELSE
RETURN 0
END IF
0 - Allow the window to be closed
1 - Prevent the window from closing

No comments:

Custom Search