SlideShare a Scribd company logo
1 of 7
Shri Pankaj
Classes

1 what is a class and an object?
   A class is a user-defined data type, which has a state (its representation or internal data) and
some operations (its behavior or its methods). An object is an instance of a class, or a variable of the
data type defined by the class. Objects are actual entities. When the program runs, objects take up
some memory for their internal representation. The relationship between object and class is the
same as the one between variable and type.
  An Object consists of method, and in many cases, properties, and events, properties represent the
data contained in the object.

2. What are the visibility options for class members? What is the difference between
them?
    Visibility determines where and how a member can be accessed, with private representing the
least accessibility, protected representing an intermediate level of accessibility, and public,
published, and automated representing the greatest accessibility.
     You can increase the visibility of a member in a descendant class by redeclaring it, but you
cannot decrease its visibility.

3. Is it possible to use private member of class in some other class? If Classes are declared
in the same unit? ------ Yes
4. Can we change the visibility of members in the descendent classes? ----- No
5. Can I have a class with more than one constructor? ------ Yes

6. Class function. Why we use it?
      It's important to know how these functions are called when you create an object, because you
can hook in two different steps. As you call a constructor, Delphi invokes the New Instance virtual
class function, defined in TObject. Because this is a virtual function, you can modify the memory
manager for a specific class by overriding it. To perform the memory allocation, however, New
Instance typically ends up calling the GetMem function of the active memory manager, which
provides you with your second chance to customize the standard behavior.

7. What is use of inheritance?
   We often need to use a slightly different version of an existing class that we have written or that
someone has given to us. For example, you might need to add a new method or slightly change an
existing one. You can do this easily by modifying the original code, unless you want to be able to use
the two different versions of the class in different circumstances.
   A typical alternative is to make a copy of the original type definition, change its code to support
the new features, and give a new name to the resulting class. This might work, but it also might
create problems: In duplicating the code you also duplicate the bugs; and if you want to add a new
feature, you’ll need to add it two or more times, depending on the number of copies of the original
code you’ve made. This approach results in two completely different data types, so the compiler
cannot help you take advantage of the similarities between the two types.
    To solve these kinds of problems in expressing similarities between classes, Object Pascal
allows you to define a new class directly from an existing one. This technique is known as
inheritance (or subclassing) and is one of the fundamental elements of object-oriented
programming languages. To inherit from an existing class, you only need to indicate that class at
the beginning of the declaration of the subclass.
8. We have two classes. A and B = Class(A). Now you have created one variable of for each
class. Now can you say B1 = A1. -------- No.

9. What do you by Abstract Classes?
   When we will never want to instantiate objects of a base class, we call it an abstract class. Such a
class exists only to act as a parent of derived classes that will be used to instantiate objects. It may
also provide an interface for the class hierarchy.

10. Can you make an object of abstract classes? ---------- (Yes, Warning)
11. Can we define an abstract method without a virtual keyword? --------- (No)
12. Is it compulsory to define all the abstract method in the descendent classes? ----- (Yes)

Interface

1. Can we declare variables in interface? ----- (No, Only Properties and method are allowed)
2. Can we declare read-only property? -------- (Yes)
3. Can we have private, published or protected method? ------ (No, Only public allowed)

Constructor

 1. What do you mean by constructor?
      As I’ve mentioned, to allocate the memory for the object, we call the Create method.
This is a constructor, a special method that you can apply to a class to allocate memory for an
instance of that class. The instance is returned by the constructor and can be assigned to a variable
for storing the object and using it later on. The default TObject. Create constructor initializes all the
data of the new instance to zero.
    If you want your instance data to start out with a nonzero value, then you need to write a custom
constructor to do that.
    Although you can use any name for a constructor, you should stick to the standard name, Create.
Although the declaration specifies no return value, a constructor returns a reference to the object it
creates or is called in.

2. Can we overload constructor? ---- ( No)
3. Can we define it as a virtual function? What is the use? ------ (Yes)
4. How we can create an object dynamically?

Virtual

1. What is virtual function?
     Virtual means existing in appearance but not in reality. When virtual functions are used, a
program that appears to be calling a function of one class may in reality be calling a function of a
different class. Why are needed ------Suppose you have a number of objects of different classes but
you want to put them all in an array and perform a particular operation on then using the same
function call.
    A more complicated and more flexible, dispatch mechanism than static method. Can be redefined
in descendent classes, but still be called in the ancestor class and object where the method is
defining looks up the address at runtime.
2. What is Dynamic function?
    Virtual and dynamic methods, unlike static methods, can be overridden in descendant classes.
When an overridden method is called, the actual (runtime) type of the class or object used in the
method call--not the declared type of the variable--determines which implementation to activate.
   To override a method, redeclare it with the override directive. An override declaration must match
the ancestor declaration in the order and type of its parameters and in its result type (if any).

3. You have two classes. A and B. B = Class (A); One virtual function let say Test is
declared here. Now if you have declared two object of class A
     Var A1, A2: A;
      Begin
         A1 := A.Create;              A2 :=B.Create ;
         A1.test; // Will call a test      A2.test; // Will call b.test end;
What will be output?

5. Can we overload a virtual function? ---- (Yes)

 6. How can be override virtual function?
     You can override virtual methods in subclasses by using the override directive. If you don’t use
virtual methods, you can still provide a new implementation in a subclass by redeclaring the
interface type in the subclass, rebinding the interface methods to new versions of the static methods.
At first sight, using virtual methods to implement interfaces seems to allow for smoother coding in
subclasses, but both approaches are equally powerful and flexible.

7. Suppose you have two classes. Class B is inherited from class A. In class a you have
one virtual function let’s say Draw. Can you declare the same virtual function in class B.
   [Warning] Unit1.pas (36). Method ‘draw’ hides virtual method of base type ‘A’.

7. What is the solution if you still want to declare this function is class B.
   Use Reintroduce

    Type
    T1-class(TObject)
         Procedure Test (I: Integer); Overload; virtual;
     End;
    T2 = class (T1)
         Procedure Test (I: Integer); Reintroduce; Overload;
    End;
    ----
    SomeObject: = T2.Create;
    SomeObject.Test(‘Hello’);     /// Calls T2.Test
    SomeObject.Test(7);              ///Calls T1.Test

Reintroduce: To avoid this message and to instruct the compiler more precisely on your intentions,
you can use the reintroduce directive. Reintroduce directive suppresses compiler warring about
hiding previously declared virtual method.
Overload

1. What is Overloading?
    Object Pascal supports overloaded functions and methods: you can have multiple methods with
the same name, provided that the parameters are different. By checking the parameters, the
compiler can determine which of the versions of the routine you want to call.
   There are two basic rules:
   - Each version of the method must be followed by the overload keyword.
   - The differences must be in the number or type of the parameters or both. The return type
cannot be used to distinguish between two methods.
  Overloading can be applied to global functions and procedures and to methods of a class.

2. What conditions must be satisfied, in order to declare an overloaded function?
3. Can we use default parameter in overloading? ---- Yes

Polymorphism:
     Polymorphism means you can write a call to a method, applying it to a variable, but which
method Delphi actually calls depends on the type of the object the variable relates to. Delphi cannot
determine until run time the actual class of the object the variable refers to, because of the type-
compatibility rule discussed in the previous section.

Late Binding:
   This means that a method call is resolved by the compiler and linker, which replace the request
with a call to the specific memory location where the function or procedure resides. (This is known
as the address of the function.) OOP languages allow the use of another form of binding, known as
dynamic or late binding. In this case, the actual address of the method to be called is determined
at run time based on the type of the instance used to make the call.

Encapsulation:
    A class can have any amount of data and any number of methods. However, for a good object
oriented approach, data should be hidden, or encapsulated, inside the class using it. Using methods
to access the internal representation of an object limits the risk of generating erroneous situations,
as the methods can check whether the date is valid and refuse to modify the new value if it is not.
Encapsulation is important because it allows the class writer to modify the internal representation
in a future version.
   The concept of encapsulation is often indicated by the idea of a “black box,” where you don’t know
about the internals: You only know how to interface with it or how to use it regardless of its internal
structure. The “how to use” portion, called the class interface, allows other parts of a program to
access and use the objects of that class. However, when you use the objects, most of their code is
hidden. You seldom know what internal data the object has, and you usually have no way to access
the data directly.
Property

1. Property / Public. Why we use it?
   Property: A property, like a field, defines an attribute of an object. But while a field is merely a
storage location whose contents can be examined and changed, a property associates specific actions
with reading or modifying its data. Properties provide control over access to an object's attributes,
and they allow attributes to be computed.
    Properties are defined by their access specifies. Unlike fields, properties cannot be passed as var
parameters, nor can the @ operator be applied to a property. The reason is that a property doesn't
necessarily exist in memory. It could, for instance, have a read method that retrieves a value from a
database or generates a random value.

   Private, protected, and public members:
       A private member is invisible outside of the unit or program where its class is declared. In
other words, a private method cannot be called from another module, and a private field or property
cannot be read or written to from another module. By placing related class declarations in the same
module, you can give the classes’ access to one another's private members without making those
members more widely accessible.

A protected member is visible anywhere in the module where its class is declared and from any
descendant class, regardless of the module where the descendant class appears. A protected method
can be called, and a protected field or property read or written to, from the definition of any method
belonging to a class that descends from the one where the protected member is declared. Members
that are intended for use only in the implementation of derived classes are usually protected.

A public member is visible wherever its class can be referenced.

2. Read only Property?
   The write directive of a property can be omitted, making it a read-only property. The compiler will
issue an error if you try to change it. You can also omit the read directive and define a write-only
property, but that doesn’t make much sense and is used infrequently.

3. Can we overload property? ---- (No)
4. Can we override a property? ----- (Declare the property with specifying the type )

VCL

2. Who is the ultimate of all VCL objects and components? -------- (Tobject)
3. For creating a new component which is visible to the user at runtime which class
should be use as the base class? ----- (Tobject, Tcontrol or TComponent) (Tcontrol)

4. I have a from and on this form I have two buttons and one panel. On the panel I have
one more button. Form1.Controlcount; Form1.Componentcount?
   (Controlcount gives parent, component count gives owner) Componentcount = 4; Controlcount = 3
(Two buttons and one panel).
    Panel1.controlcount =1; Panel1.componentcount =0 (even though buttons is placed on the panel,
owner is form1)
Forms

2. Can we change owner at runtime? ------ No Change.
3. You have tow forms on form1 you have a button. How can you move it to form2? --- Yes
4. After this suppose you have closed Form1. What will be effect on button1? When you
close Form2 will it generate any error? ---
5. Can we delete a component introduced in the base form? ---- No delete in inherited form.
6. Can we edit DFM manually? ----- Yes.

Exception Handling

The benefit of an exception handling system as used in Delphi is that applications can, despite of a
run time error, keep running without crashing.
The application can close normally and data can be saved.

Delphi generates an exception when a runtime error occurs.
This exception can be solved in the code. (You have to program that yourself of course)
When the code does nothing the error ’floats’ up to the calling code.
This goes on and on until there is no code anymore, at that time Delphi will try to solve the problem.

The system
The next keywords belong to the exception handling system:
try is the beginning of the protected code.
except is the end of this code
finally is code that must be executed, even if an error occurs.
raise give you the possibility to generate an exception manually.

1. Can we have Try, Except and finally block together? --- No.
   Try – Finally:
This block guaranties that the code after finally will be executed even if a runtime error shows up.
This block is important for resource protection. For example for freeing of objects, like a form.

Sometimes you want to ensure that specific parts of an operation are completed, whether or not the
operation is interrupted by an exception. For example, when a routine acquires control of a resource,
it is often important that the resource be released, regardless of whether the routine terminates
normally. In these situations, you can use a try...finally statement.

  Try- Except:
When the code in the try part doesn't generate an error then the code in de except part will never be
used.
If an error occurs the program will continue after except.
The error can be determined and solved.
The user will not see the by Delphi generated exception. (That one is destroyed)
So excepts allows a solution for the error and a friendly message to the user.

The exception handling block starts with the except keyword and ends with the keyword end. These
two keywords are actually part of the same statement as the try block. That is, both the try block
and the exception handling block are considered part of a single try...except statement.
Raise:
Raise can be used to re-raise an exception. The exception can be handled evenly.
You can also use raise to generate exceptions manually: raise EDiveByZero.Create ('Divide by
zero');

2. Can we use keyword raise in Try Block? ---- Yes.

3. What is RTTI?
        Runtime type information (RTTI) is generated for published members. RTTI allows an
application to query the fields and properties of an object dynamically and to locate its methods.
RTTI is used to access the values of properties when saving and loading form files, to display
properties in the Object Inspector, and to associate specific methods (called event handlers) with
specific properties (called events).

        The TPersistent class defined in the Classes unit of the component library is declared in the
state, so any class derived from TPersistent will have RTTI generated for its published sections. The
component library uses the runtime type information generated for published sections to access the
values of a component's properties when saving or loading form files. Furthermore, the IDE uses a
component's runtime type information to determine the list of properties to show in the Object
Inspector.

More Related Content

What's hot

Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1Sherihan Anver
 
Top 20 c# interview Question and answers
Top 20 c# interview Question and answersTop 20 c# interview Question and answers
Top 20 c# interview Question and answersw3asp dotnet
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in javaAhsan Raja
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7Vince Vo
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism JavaM. Raihan
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and objectFajar Baskoro
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+javaYe Win
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interfacemanish kumar
 
Seminar on java
Seminar on javaSeminar on java
Seminar on javashathika
 

What's hot (20)

Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
Top 20 c# interview Question and answers
Top 20 c# interview Question and answersTop 20 c# interview Question and answers
Top 20 c# interview Question and answers
 
C# interview questions
C# interview questionsC# interview questions
C# interview questions
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
Unit3
Unit3Unit3
Unit3
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
 
My c++
My c++My c++
My c++
 
OOP java
OOP javaOOP java
OOP java
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
 
core java for hadoop
core java for hadoopcore java for hadoop
core java for hadoop
 
Seminar on java
Seminar on javaSeminar on java
Seminar on java
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
 

Viewers also liked

Torre Jussana. Jornada Esplai i municipi
Torre Jussana. Jornada Esplai i municipiTorre Jussana. Jornada Esplai i municipi
Torre Jussana. Jornada Esplai i municipiSuportAssociatiu
 
SVE: progetto "Side by side"
SVE: progetto "Side by side"SVE: progetto "Side by side"
SVE: progetto "Side by side"Novella Benedetti
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakShelly Sanchez Terrell
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 

Viewers also liked (6)

Torre Jussana. Jornada Esplai i municipi
Torre Jussana. Jornada Esplai i municipiTorre Jussana. Jornada Esplai i municipi
Torre Jussana. Jornada Esplai i municipi
 
SVE: progetto "Side by side"
SVE: progetto "Side by side"SVE: progetto "Side by side"
SVE: progetto "Side by side"
 
Inaugural Addresses
Inaugural AddressesInaugural Addresses
Inaugural Addresses
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & Textspeak
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Similar to Delphi qa (20)

Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Classes2
Classes2Classes2
Classes2
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Java basics
Java basicsJava basics
Java basics
 
Oops
OopsOops
Oops
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
 
Application package
Application packageApplication package
Application package
 
Java 06
Java 06Java 06
Java 06
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
 
Mca2030 object oriented programming – c++
Mca2030  object oriented programming – c++Mca2030  object oriented programming – c++
Mca2030 object oriented programming – c++
 
Java mcq
Java mcqJava mcq
Java mcq
 
Oops
OopsOops
Oops
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
Reflection
ReflectionReflection
Reflection
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
 
Ruby object model
Ruby object modelRuby object model
Ruby object model
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
Intervies
InterviesIntervies
Intervies
 
Only oop
Only oopOnly oop
Only oop
 

Recently uploaded

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 

Recently uploaded (20)

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 

Delphi qa

  • 1. Shri Pankaj Classes 1 what is a class and an object? A class is a user-defined data type, which has a state (its representation or internal data) and some operations (its behavior or its methods). An object is an instance of a class, or a variable of the data type defined by the class. Objects are actual entities. When the program runs, objects take up some memory for their internal representation. The relationship between object and class is the same as the one between variable and type. An Object consists of method, and in many cases, properties, and events, properties represent the data contained in the object. 2. What are the visibility options for class members? What is the difference between them? Visibility determines where and how a member can be accessed, with private representing the least accessibility, protected representing an intermediate level of accessibility, and public, published, and automated representing the greatest accessibility. You can increase the visibility of a member in a descendant class by redeclaring it, but you cannot decrease its visibility. 3. Is it possible to use private member of class in some other class? If Classes are declared in the same unit? ------ Yes 4. Can we change the visibility of members in the descendent classes? ----- No 5. Can I have a class with more than one constructor? ------ Yes 6. Class function. Why we use it? It's important to know how these functions are called when you create an object, because you can hook in two different steps. As you call a constructor, Delphi invokes the New Instance virtual class function, defined in TObject. Because this is a virtual function, you can modify the memory manager for a specific class by overriding it. To perform the memory allocation, however, New Instance typically ends up calling the GetMem function of the active memory manager, which provides you with your second chance to customize the standard behavior. 7. What is use of inheritance? We often need to use a slightly different version of an existing class that we have written or that someone has given to us. For example, you might need to add a new method or slightly change an existing one. You can do this easily by modifying the original code, unless you want to be able to use the two different versions of the class in different circumstances. A typical alternative is to make a copy of the original type definition, change its code to support the new features, and give a new name to the resulting class. This might work, but it also might create problems: In duplicating the code you also duplicate the bugs; and if you want to add a new feature, you’ll need to add it two or more times, depending on the number of copies of the original code you’ve made. This approach results in two completely different data types, so the compiler cannot help you take advantage of the similarities between the two types. To solve these kinds of problems in expressing similarities between classes, Object Pascal allows you to define a new class directly from an existing one. This technique is known as inheritance (or subclassing) and is one of the fundamental elements of object-oriented programming languages. To inherit from an existing class, you only need to indicate that class at the beginning of the declaration of the subclass.
  • 2. 8. We have two classes. A and B = Class(A). Now you have created one variable of for each class. Now can you say B1 = A1. -------- No. 9. What do you by Abstract Classes? When we will never want to instantiate objects of a base class, we call it an abstract class. Such a class exists only to act as a parent of derived classes that will be used to instantiate objects. It may also provide an interface for the class hierarchy. 10. Can you make an object of abstract classes? ---------- (Yes, Warning) 11. Can we define an abstract method without a virtual keyword? --------- (No) 12. Is it compulsory to define all the abstract method in the descendent classes? ----- (Yes) Interface 1. Can we declare variables in interface? ----- (No, Only Properties and method are allowed) 2. Can we declare read-only property? -------- (Yes) 3. Can we have private, published or protected method? ------ (No, Only public allowed) Constructor 1. What do you mean by constructor? As I’ve mentioned, to allocate the memory for the object, we call the Create method. This is a constructor, a special method that you can apply to a class to allocate memory for an instance of that class. The instance is returned by the constructor and can be assigned to a variable for storing the object and using it later on. The default TObject. Create constructor initializes all the data of the new instance to zero. If you want your instance data to start out with a nonzero value, then you need to write a custom constructor to do that. Although you can use any name for a constructor, you should stick to the standard name, Create. Although the declaration specifies no return value, a constructor returns a reference to the object it creates or is called in. 2. Can we overload constructor? ---- ( No) 3. Can we define it as a virtual function? What is the use? ------ (Yes) 4. How we can create an object dynamically? Virtual 1. What is virtual function? Virtual means existing in appearance but not in reality. When virtual functions are used, a program that appears to be calling a function of one class may in reality be calling a function of a different class. Why are needed ------Suppose you have a number of objects of different classes but you want to put them all in an array and perform a particular operation on then using the same function call. A more complicated and more flexible, dispatch mechanism than static method. Can be redefined in descendent classes, but still be called in the ancestor class and object where the method is defining looks up the address at runtime.
  • 3. 2. What is Dynamic function? Virtual and dynamic methods, unlike static methods, can be overridden in descendant classes. When an overridden method is called, the actual (runtime) type of the class or object used in the method call--not the declared type of the variable--determines which implementation to activate. To override a method, redeclare it with the override directive. An override declaration must match the ancestor declaration in the order and type of its parameters and in its result type (if any). 3. You have two classes. A and B. B = Class (A); One virtual function let say Test is declared here. Now if you have declared two object of class A Var A1, A2: A; Begin A1 := A.Create; A2 :=B.Create ; A1.test; // Will call a test A2.test; // Will call b.test end; What will be output? 5. Can we overload a virtual function? ---- (Yes) 6. How can be override virtual function? You can override virtual methods in subclasses by using the override directive. If you don’t use virtual methods, you can still provide a new implementation in a subclass by redeclaring the interface type in the subclass, rebinding the interface methods to new versions of the static methods. At first sight, using virtual methods to implement interfaces seems to allow for smoother coding in subclasses, but both approaches are equally powerful and flexible. 7. Suppose you have two classes. Class B is inherited from class A. In class a you have one virtual function let’s say Draw. Can you declare the same virtual function in class B. [Warning] Unit1.pas (36). Method ‘draw’ hides virtual method of base type ‘A’. 7. What is the solution if you still want to declare this function is class B. Use Reintroduce Type T1-class(TObject) Procedure Test (I: Integer); Overload; virtual; End; T2 = class (T1) Procedure Test (I: Integer); Reintroduce; Overload; End; ---- SomeObject: = T2.Create; SomeObject.Test(‘Hello’); /// Calls T2.Test SomeObject.Test(7); ///Calls T1.Test Reintroduce: To avoid this message and to instruct the compiler more precisely on your intentions, you can use the reintroduce directive. Reintroduce directive suppresses compiler warring about hiding previously declared virtual method.
  • 4. Overload 1. What is Overloading? Object Pascal supports overloaded functions and methods: you can have multiple methods with the same name, provided that the parameters are different. By checking the parameters, the compiler can determine which of the versions of the routine you want to call. There are two basic rules: - Each version of the method must be followed by the overload keyword. - The differences must be in the number or type of the parameters or both. The return type cannot be used to distinguish between two methods. Overloading can be applied to global functions and procedures and to methods of a class. 2. What conditions must be satisfied, in order to declare an overloaded function? 3. Can we use default parameter in overloading? ---- Yes Polymorphism: Polymorphism means you can write a call to a method, applying it to a variable, but which method Delphi actually calls depends on the type of the object the variable relates to. Delphi cannot determine until run time the actual class of the object the variable refers to, because of the type- compatibility rule discussed in the previous section. Late Binding: This means that a method call is resolved by the compiler and linker, which replace the request with a call to the specific memory location where the function or procedure resides. (This is known as the address of the function.) OOP languages allow the use of another form of binding, known as dynamic or late binding. In this case, the actual address of the method to be called is determined at run time based on the type of the instance used to make the call. Encapsulation: A class can have any amount of data and any number of methods. However, for a good object oriented approach, data should be hidden, or encapsulated, inside the class using it. Using methods to access the internal representation of an object limits the risk of generating erroneous situations, as the methods can check whether the date is valid and refuse to modify the new value if it is not. Encapsulation is important because it allows the class writer to modify the internal representation in a future version. The concept of encapsulation is often indicated by the idea of a “black box,” where you don’t know about the internals: You only know how to interface with it or how to use it regardless of its internal structure. The “how to use” portion, called the class interface, allows other parts of a program to access and use the objects of that class. However, when you use the objects, most of their code is hidden. You seldom know what internal data the object has, and you usually have no way to access the data directly.
  • 5. Property 1. Property / Public. Why we use it? Property: A property, like a field, defines an attribute of an object. But while a field is merely a storage location whose contents can be examined and changed, a property associates specific actions with reading or modifying its data. Properties provide control over access to an object's attributes, and they allow attributes to be computed. Properties are defined by their access specifies. Unlike fields, properties cannot be passed as var parameters, nor can the @ operator be applied to a property. The reason is that a property doesn't necessarily exist in memory. It could, for instance, have a read method that retrieves a value from a database or generates a random value. Private, protected, and public members: A private member is invisible outside of the unit or program where its class is declared. In other words, a private method cannot be called from another module, and a private field or property cannot be read or written to from another module. By placing related class declarations in the same module, you can give the classes’ access to one another's private members without making those members more widely accessible. A protected member is visible anywhere in the module where its class is declared and from any descendant class, regardless of the module where the descendant class appears. A protected method can be called, and a protected field or property read or written to, from the definition of any method belonging to a class that descends from the one where the protected member is declared. Members that are intended for use only in the implementation of derived classes are usually protected. A public member is visible wherever its class can be referenced. 2. Read only Property? The write directive of a property can be omitted, making it a read-only property. The compiler will issue an error if you try to change it. You can also omit the read directive and define a write-only property, but that doesn’t make much sense and is used infrequently. 3. Can we overload property? ---- (No) 4. Can we override a property? ----- (Declare the property with specifying the type ) VCL 2. Who is the ultimate of all VCL objects and components? -------- (Tobject) 3. For creating a new component which is visible to the user at runtime which class should be use as the base class? ----- (Tobject, Tcontrol or TComponent) (Tcontrol) 4. I have a from and on this form I have two buttons and one panel. On the panel I have one more button. Form1.Controlcount; Form1.Componentcount? (Controlcount gives parent, component count gives owner) Componentcount = 4; Controlcount = 3 (Two buttons and one panel). Panel1.controlcount =1; Panel1.componentcount =0 (even though buttons is placed on the panel, owner is form1)
  • 6. Forms 2. Can we change owner at runtime? ------ No Change. 3. You have tow forms on form1 you have a button. How can you move it to form2? --- Yes 4. After this suppose you have closed Form1. What will be effect on button1? When you close Form2 will it generate any error? --- 5. Can we delete a component introduced in the base form? ---- No delete in inherited form. 6. Can we edit DFM manually? ----- Yes. Exception Handling The benefit of an exception handling system as used in Delphi is that applications can, despite of a run time error, keep running without crashing. The application can close normally and data can be saved. Delphi generates an exception when a runtime error occurs. This exception can be solved in the code. (You have to program that yourself of course) When the code does nothing the error ’floats’ up to the calling code. This goes on and on until there is no code anymore, at that time Delphi will try to solve the problem. The system The next keywords belong to the exception handling system: try is the beginning of the protected code. except is the end of this code finally is code that must be executed, even if an error occurs. raise give you the possibility to generate an exception manually. 1. Can we have Try, Except and finally block together? --- No. Try – Finally: This block guaranties that the code after finally will be executed even if a runtime error shows up. This block is important for resource protection. For example for freeing of objects, like a form. Sometimes you want to ensure that specific parts of an operation are completed, whether or not the operation is interrupted by an exception. For example, when a routine acquires control of a resource, it is often important that the resource be released, regardless of whether the routine terminates normally. In these situations, you can use a try...finally statement. Try- Except: When the code in the try part doesn't generate an error then the code in de except part will never be used. If an error occurs the program will continue after except. The error can be determined and solved. The user will not see the by Delphi generated exception. (That one is destroyed) So excepts allows a solution for the error and a friendly message to the user. The exception handling block starts with the except keyword and ends with the keyword end. These two keywords are actually part of the same statement as the try block. That is, both the try block and the exception handling block are considered part of a single try...except statement.
  • 7. Raise: Raise can be used to re-raise an exception. The exception can be handled evenly. You can also use raise to generate exceptions manually: raise EDiveByZero.Create ('Divide by zero'); 2. Can we use keyword raise in Try Block? ---- Yes. 3. What is RTTI? Runtime type information (RTTI) is generated for published members. RTTI allows an application to query the fields and properties of an object dynamically and to locate its methods. RTTI is used to access the values of properties when saving and loading form files, to display properties in the Object Inspector, and to associate specific methods (called event handlers) with specific properties (called events). The TPersistent class defined in the Classes unit of the component library is declared in the state, so any class derived from TPersistent will have RTTI generated for its published sections. The component library uses the runtime type information generated for published sections to access the values of a component's properties when saving or loading form files. Furthermore, the IDE uses a component's runtime type information to determine the list of properties to show in the Object Inspector.