The document provides definitions and explanations of various object-oriented programming concepts in Delphi such as classes, objects, visibility of class members, inheritance, abstract classes, interfaces, constructors, virtual functions, polymorphism, late binding, encapsulation, properties, exceptions handling, and runtime type information (RTTI). It discusses these concepts through questions and answers. Key points covered include the relationship between classes and objects, differences between visibility levels of class members, how inheritance allows the creation of subclasses, rules around abstract classes and methods, limitations of interfaces, how to define and overload constructors and functions, use of virtual functions and polymorphism, and how RTTI is used.
oops concept in java | object oriented programming in javaCPD INDIA
object oriented programming is a key concept for the development of application in windows as well as web based application environment. oops concept maps real world through its concept of classes, objects, inheritance, polymorphism which help in making a robust application.
oops concept in java | object oriented programming in javaCPD INDIA
object oriented programming is a key concept for the development of application in windows as well as web based application environment. oops concept maps real world through its concept of classes, objects, inheritance, polymorphism which help in making a robust application.
Top 20 c# interview Question and answersw3asp dotnet
This presentation contains interview question and answers . www.w3asp.net provide you the information, knowledge, job, practices and tranings regarding asp.net.
Ideal for learning the basics of java, and can also be used as a school project for class 10 and 12. The document contains illustrative pictures, and carefully selected information to make the basics of java strong. Pls ignore small spelling mistakes made.
Lecture 8 abstract class and interfacemanish kumar
Abstract class and Interface both are used to achieve the concept of abstraction and using the interface we can implement the concept of multiple inheritance in java.
Top 20 c# interview Question and answersw3asp dotnet
This presentation contains interview question and answers . www.w3asp.net provide you the information, knowledge, job, practices and tranings regarding asp.net.
Ideal for learning the basics of java, and can also be used as a school project for class 10 and 12. The document contains illustrative pictures, and carefully selected information to make the basics of java strong. Pls ignore small spelling mistakes made.
Lecture 8 abstract class and interfacemanish kumar
Abstract class and Interface both are used to achieve the concept of abstraction and using the interface we can implement the concept of multiple inheritance in java.
We looked at the data. Here’s a breakdown of some key statistics about the nation’s incoming presidents’ addresses, how long they spoke, how well, and more.
My books- Hacking Digital Learning Strategies http://hackingdls.com & Learning to Go https://gum.co/learn2go
Resources at http://shellyterrell.com/emoji
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
We asked LinkedIn members worldwide about their levels of interest in the latest wave of technology: whether they’re using wearables, and whether they intend to buy self-driving cars and VR headsets as they become available. We asked them too about their attitudes to technology and to the growing role of Artificial Intelligence (AI) in the devices that they use. The answers were fascinating – and in many cases, surprising.
This SlideShare explores the full results of this study, including detailed market-by-market breakdowns of intention levels for each technology – and how attitudes change with age, location and seniority level. If you’re marketing a tech brand – or planning to use VR and wearables to reach a professional audience – then these are insights you won’t want to miss.
Artificial intelligence (AI) is everywhere, promising self-driving cars, medical breakthroughs, and new ways of working. But how do you separate hype from reality? How can your company apply AI to solve real business problems?
Here’s what AI learnings your business should keep in mind for 2017.
Dear students get fully solved assignments
Send your semester & Specialization name to our mail id :
“ help.mbaassignments@gmail.com ”
or
Call us at : 08263069601
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
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.