What are the differences between public, private, protected, static, transient, final and volatile? | PHP

Public: Public declared items can be accessed everywhere.
Protected: Protected limits access to inherited and parent classes (and to the class that defines the item).
Private: Private limits visibility only to the class that defines the item.
Static: A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope.
Final: Final keyword prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.
transient: A transient variable is a variable that may not be serialized.
volatile: a variable that might be concurrently modified by multiple threads should be declared volatile. Variables declared to be volatile will not be optimized by the compiler because their value can change at any time.

What is the use of friend function? | PHP


   Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class.
  A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.
 

What are the differences between procedure-oriented languages and object-oriented languages? | PHP

There are lot of difference between procedure language and object oriented like below

  1. Procedure language easy for new developer but complex to understand whole software as compare to object oriented model.
  2. In Procedure language it is difficult to use design pattern mvc , Singleton pattern etc but in OOP you we able to develop design pattern.
  3. IN OOP language we able to ree use code like Inheritance ,polymorphism etc but this type of thing not available in procedure language on that our Fonda use COPY and PASTE .

What are the features and advantages of object-oriented programming? | PHP

One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It
allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns.
For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system

How can we encrypt the username and password using PHP? | PHP

The functions in this section perform encryption and decryption, and compression and uncompression:
encryption decryption
AES_ENCRYT() AES_DECRYPT()
ENCODE() DECODE()
DES_ENCRYPT() DES_DECRYPT()
ENCRYPT() Not available
MD5() Not available
OLD_PASSWORD() Not available
PASSWORD() Not available
SHA() or SHA1() Not available
Not available UNCOMPRESSED_LENGTH()

How can we encrypt and decrypt a data present in a MySQL table using MySQL? | PHP

AES_ENCRYPT () and AES_DECRYPT ()

What are the reasons for selecting lamp (Linux, apache, MySQL, PHP) instead of combination of other software programs, servers and operating systems? | PHP

All of those are open source resource. Security of Linux is veryv ery more than windows. Apache is a better server that IIS both in functionality and security. MySQL is world most popular open source database. PHP is more faster that asp or any other scripting language.

How we get IP address of client, previous reference page etc ? | PHP

By using $_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_REFERER'] etc.

What is htaccess? Why do we use this and Where? | PHP

.htaccess files are configuration files of Apache Server which provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
 

What is meant by nl2br()? | PHP


Inserts HTML line breaks (<BR />) before all newlines in a string.
 

Shopping cart online validation i.e. how can we configure Paypal, etc.? | PHP


Nothing more we have to do only redirect to the payPal url after submit all information needed by paypal like amount,adresss etc.
 

Shopping cart online validation i.e. how can we configure Paypal, etc.?

Nothing more we have to do only redirect to the payPal url after submit all information needed by paypal like amount,adresss etc.
 

Suppose your Zend engine supports the mode <? ?> Then how can u configure your PHP Zend engine to support <?PHP ?> mode ?


In php.ini file:
set
short_open_tag=on
to make PHP support

How can I execute a PHP script using command line? |PHP


Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument.
 

What is use of header() function in php ? |PHP


The header() function sends a raw HTTP header to a client.We can use herder() function for redirection of pages. It is important to notice that header() must be called before any actual output is seen..
 

What are the different tables(Engine) present in MySQL, which one is default? |PHP What are the different tables(Engine) present in MySQL, which one is default?


 Following tables (Storage Engine) we can create
1. MyISAM(The default storage engine IN MYSQL Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type. An .frm file stores the table format. The data file has an .MYD (MYData) extension. The index file has an .MYI (MYIndex) extension. )
2. InnoDB(InnoDB is a transaction-safe (ACID compliant) storage engine for MySQL that has commit, rollback, and crash-recovery capabilities to protect user data.)
3. Merge
4. Heap (MEMORY)(The MEMORY storage engine creates tables with contents that are stored in memory. Formerly, these were known as HEAP tables. MEMORY is the preferred term, although HEAP remains supported for backward compatibility. )
5. BDB (BerkeleyDB)(Sleepycat Software has provided MySQL with the Berkeley DB transactional storage engine. This storage engine typically is called BDB for short. BDB tables may have a greater chance of surviving crashes and are also capable of COMMIT and ROLLBACK operations on transactions)
6. EXAMPLE
7. FEDERATED (It is a storage engine that accesses data in tables of remote databases rather than in local tables. )
8. ARCHIVE (The ARCHIVE storage engine is used for storing large amounts of data without indexes in a very small footprint. )
9. CSV (The CSV storage engine stores data in text files using comma-separated values format.)
10. BLACKHOLE (The BLACKHOLE storage engine acts as a "black hole" that accepts data but throws it away and does not store it. Retrievals always return an empty result)
 

Can we use include ("xyz.PHP") two times in a PHP page "index.PHP"? | PHP

 Yes we can use include("xyz.php") more than one time in any page. but it create a prob when xyz.php file contain some funtions declaration then error will come for already declared function in this file else not a prob like if you want to show same content two time in page then must incude it two time not a problem.
 

What are the differences between require and include? | PHP

Both include and require used to include a file but when included file not found include end Warning where as Require send Fatal Error .

How can we create a database using PHP and MySQL?


We can create MySQL database with the use of
mysql_create_db("Database Name")
 

How can we extract string "pcds.co.in " from a string "http://info@pcds.co.in using regular expression of PHP?


preg_match("/^http:\/\/.+@(.+)$/","http://info@pcds.co.in",$matches);
echo $matches[1];
 

What are the differences between Get and post methods? | PHP


There are some defference between GET and POST method
1. GET Method have some limit like only 2Kb data able to send for request.But in POST method unlimited data can we send
2. when we use GET method requested data show in url but Not in POST method so POST method is good for send sensetive request

What is the difference between mysql_fetch_object and mysql_fetch_array? | PHP


mysql_fetch_object() is similar tomysql_fetch_array(), with one difference -an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).

In how many ways we can retrieve the data in the result set of MySQL using PHP? | PHP


We can do it by 4 Ways
1. mysql_fetch_row. , 2. mysql_fetch_array , 3. mysql_fetch_object
4. mysql_fetch_assoc

What is the difference between $name and $$name? | PHP

$name is variable where as $$name is reference variable like $name=sonia and $$name=singh so $sonia value is singh.
 

Who is the father of PHP ? PHP


Rasmus Lerdorf is known as the father of PHP.
 

PHP Interview Questions and Answers for Freshers and Experienced

1. What is PHP?
2. What Is a Session?
3. What is meant by PEAR in php?
4. How can we know the number of days between two given dates using PHP?
5. How can we repair a MySQL table?
6. What is the difference between $message and $$message?
7. What Is a Persistent Cookie?
8. What does a special set of tags do in PHP?
9. How do you define a constant?
10. What is meant by urlencode and urldecode?
11. How To Get the Uploaded File Information in the Receiving Script? 
12. What is the difference between mysql_fetch_object and mysql_fetch_array?
13. How can I execute a PHP script using command line?
14. What are the different tables present in MySQL? 

15. How To Create a Table? 
16. How can we encrypt the username and password using PHP?
17. How do you pass a variable by value? 
18. When are you supposed to use endif to end the conditional statement?
19. How can we send mail using JavaScript?
20. What is the functionality of the function strstr and stristr?
21. What is the difference between ereg_replace() and eregi_replace()?
22. How do I find out the number of parameters passed into function9. ?
23. Write a select query that will be displayed the duplicated site name and how many times it is duplicated? … 
24. How To Protect Special Characters in Query String?
25. Are objects passed by value or by reference?
26. What are the differences between DROP a table and TRUNCATE a table?
27. What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods?
28. WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?
29. What’s the special meaning of __sleep and __wakeup?
30. How can we submit a form without a submit button?
31. Would you initialize your strings with single quotes or double quotes?
32. What is the difference between the functions unlink and unset?
33. How come the code works, but doesn’t for two-dimensional array of mine?
34. How can we register the variables into a session?
35. What is the difference between characters \023 and \x23?
36. How can we submit form without a submit button?
37. How can we create a database using PHP and mysql?
38. How many ways we can retrieve the date in result set of mysql using php?
39. What’s the output of the ucwords function in this example?
40. What’s the difference between htmlentities() and htmlspecialchars()?
41. What are the different functions in sorting an array?
42. How can we know the count/number of elements of an array?
43. How many ways we can pass the variable through the navigation between the pages?
44. What is the maximum length of a table name, a database name, or a field name in MySQL?
45. How many values can the SET function of MySQL take?
46. What are the other commands to know the structure of a table using MySQL commands except EXPLAIN command?
47. What’s the difference between md5(), crc32() and sha1() crypto on PHP?
48. How can we find the number of rows in a result set using PHP?
49. How many ways we can we find the current date using MySQL?
50. Give the syntax of GRANT commands?
51. What is the value for this auto incremented field user_pri_id?
52. What is the difference between CHAR and VARCHAR data types?
53. How can we encrypt and decrypt a data present in a mysql table using mysql?
54. Will comparison of string "10" and integer 11 work in PHP?
55. What is the functionality of MD5 function in PHP?
56. How can I load data from a text file into a table?
57. How can we know the number of days between two given dates using MySQL? 
58. How can we change the name of a column of a table?
59. How can we change the data type of a column of a table?
60. What is the difference between GROUP BY and ORDER BY in SQL?
61. What is meant by MIME?
62. How can we know that a session is started or not?
63. What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
64. What are the MySQL database files stored in system ?
65. What is the difference between PHP4 and PHP5?
66. Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?
67. What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
68. What is meant by nl2br()? 
69. How can we encrypt and decrypt a data presented in a table using MySQL?
70. How can I retrieve values from one database server and store them in other database server using PHP?
71. IN HOW MANY WAYS WE CAN RETRIEVE DATA IN THE RESULT SET OF MYSQL USING PHP?
72. What are the functions for IMAP?
73. What are encryption functions in PHP?
74. What is the difference between htmlentities() and htmlspecialchars()?
75. What is the functionality of the function htmlentities?
76. How can we get the properties (size, type, width, height) of an image using php image functions?
77. How can we increase the execution time of a php script?
78. HOW CAN WE TAKE A BACKUP OF A MYSQL TABLE AND HOW CAN WE RESTORE IT?
79. WHAT TYPES OF IMAGES THAT PHP SUPPORTS?
80. How can I know that a variable is a number or not using a JavaScript?
81. How can we submit from without a submit button?
82. How many ways can we get the value of current session id?
83. How can we destroy the cookie?
84. What are the current versions of Apache, PHP, and MySQL?
85. What are the features and advantages of OBJECT ORIENTED PROGRAMMING? 
86. What is the use of friend function?
87. How can we get second of the current time using date function?
88. What is the maximum size of a file that can be uploaded using PHP and how can we change this?
89. What are the advantages of stored procedures, triggers, indexes? 
90. What is maximum size of a database in mysql?
91. Explain normalization concept?
92. What type of inheritance that php supports?
93. How can increase the performance of MySQL select query?
94. How can we change the name of a column of a table?
95. What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?
96. How can I use the COM components in php?
97. How many ways we can give the output to a browser?
98. What is the default session time in php and how can I change it?
99. What is the difference between Reply-to and Return-path in the headers of a mail function?
100. How To Turn On the Session Support?
101. Explain the ternary conditional operator in PHP? 
102. What’s the difference between include and require?
103. How many ways can we get the value of current session id?
104. How can we destroy the cookie?
105. How To Read the Entire File into a Single String?

Should the this pointer can be used in the constructor? C++

 We can use the this pointer in the constructor in the initialization list and also in the body. However, there is a feeling that the object is not fully formed so we should not use this pointer. Let's understand the use of the this pointer with the help of the following example. The declared data members of a base class and/or the declared data members of the constructor's own class can be accessed by the constructor {body} and/or a function called from the constructor. This is possible because of the full construction of constructor's body at the time of execution. The preceding example always works.

The override in the derived class is not possible for a function called from the constructor and the {body} of a constructor which is independent of calling the virtual member function by the explicit use of the this pointer.

Please make sure that the initialization of other data member has already been done before passing the data member to another data member's initializer in this object. With the help of some straightforward language rules (independent of the specific compiler that you are using), you can confirm about the determination of initialization of data members.

Without the prior knowledge of these rules, there is no use of passing any data member from the this object.

Can we use initialization lists or assignments in a constructor? | C++

The constructor uses initialization lists. In fact, all the member objects in the initialization list should be initialized by a constructor. Let's take an example of One exception.
Consider the following constructor that initializes member object r__ using an initialization list: Harry::Harry() : "-(whatever) { }. This results in the improved performance. For example, if a member variable r_ is of the same type as the whatever expression, then the compiler do not have to make a separate copy of the object and the outcome related to the whatever expression is constructed directly inside r_.
Even if the types are not same, the compiler is able to initialize objects with initialization lists, even if the types are different than assignments.
Assignment is another way of building constructors, such as, Jimmy::Jimmy() { j_ = whatever; }. In this case, the temporary and separate objects are created as a result of the expression whatever and the temporary object is passed into the jL object's assignment operator.
By the use of an assignment operator in a constructor, the default constructor has fully constructed the member object and results in the allocation of some amount of memory by default or the opening of some default file. The major drawback of using the assignment operator is that all the work done may be lost if the whatever expression or the object of the assignment operator closes the particular file or release that memory. For example, if a wrong file is opened.

On creating an array of bird_class objects, which constructor will get called? | C++

The default constructor will get called for the bird_class.

Example:

If a normal constructor Is provided, the compiler will not create a default constructor. A constructor can be simply created with no arguments, as described in the preceding example.
No, not always. A default constructor is a constructor which takes no arguments, and it exists so that you can create objects of your new class. An example of this is a constructor that takes no parameters:
Class bred
{
public:
Bred(); //default constructor: can be called with no args
};
Another example of a default constructor is one that can take arguments, provided they are given default values: Example:
class Bred{
public
Bred(int i=3, int j=5); //Default constructor: can be called with args
};

Can one constructor of a class be called by another constructor of the same class for initializing the this object? | C++

a No, not possible. Let's understand it with the help of an example.
Take a human class. Now, we want our constructor Human::Human(char) to call another constructor of the same class, say Human: :Human(char,  int), in order that

Human::Human(char, int) would help to initialize the this object. Unfortunately, there is no way to do this in C++.
It always occur in its specific form and not the way a user wants. For example, the line Human(h, 0); does not call Human::Human(char, int) on the this object. Instead it calls Human::Human(char, int) to initialize a temporary, local object (not this), then it immediately destructs that temporary object when control flows over the ;.
Example:

If there is no default parameter for combining the two constructors, then there is a need of sharing of their common code in a private init() member function:
Another example:

How does List r; differs from List r();? | C++

Suppose that Member is the name of some class. Then, function f() declares a local member object called r:
Example:
void f()
{
list r; //local object named r (of class member)
}
//But function g()declares a function called r()that returns a member:
void g(){
member r(); //Function named r(that returns a member)
}
In the preceding code snippet, r is declared as a local variable and the other r() is declared as a function. That is the main difference.

On implementing a destructor of the derived class, is there any need for the explicit calling of the destructor for my base class?

 No, there is no need to call the destructor explicitly except in the case of placement hew. A destructor of a class, whether you explicitly define one or not, invokes a destructor automatically for base class sub objects. Base classes are destructed after member objects. In the multiple inheritance, the destruction of the direct base classes occur in the reverse order of their appearance in the inheritance list.
Example:

On implementing a destructor, is there any need for the explicit calling of the destructors for member objects? | C++

No, there is no need to call the destructor explicitly. A destructor of a class, whether you explicitly define one or not, invokes a destructor automatically for its member objects. Their destruction is done in the reverse order of their declaration in the class.
Example:
PROGRAM

How is the MVC design pattern used in Struts framework? | Java Structs

In the MVC design pattern, application flow is mediated by a central Controller. The Controller delegates requests to an appropriate handler. The handlers are tied to a Model, and each handler acts as an adapter between the request and the Model. The Model represents, or encapsulates, an application's business logic or state. Control is usually then forwarded back through the Controller to the appropriate View. The forwarding can be determined by consulting a set of mappings, usually loaded from a database or configuration file. This provides a loose coupling between the View and Model, which can make an application significantly easier to create and maintain.
Controller--Servlet controller which supplied by Struts itself; View --- what you can see on the screen, a JSP page and presentation components; Model --- System state and a business logic JavaBeans.

What is Struts? | Structs in java


Struts is a web page development framework and an open source software that helps developers build web applications quickly and easily. Struts combines Java Servlets, Java Server Pages, custom tags, and message resources into a unified framework. It is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone between.

Struts Interview Questions and Answers for Freshers & Experienced pdf

 1. What is Struts?
2.  How is the MVC design pattern used in Struts framework?
3.  Who makes the Struts?
4.  Why it called Struts?
5.  Do we need to pay the Struts if being used in commercial purpose?
6.  Describe Jakarta Struts Framework?
7.  What are the components of Struts?
8.  Describe is ActionServlet?
9.  What is an Action Class used for?
10.  What is ActionForm?
11.   What are the core classes of Struts?
12.  What is the design role played by Struts?
13.  How Struts control data flow?
14.  What configuration files are used in Struts?
15.  What helpers in the form of JSP pages are provided in Struts framework?
16.  What is Struts Validator Framework?
17.  What are the core classes of the Struts Framework?
18.  What are Tag Libraries provided with Struts?
19.  What are difference between ActionErrors and ActionMessage?
20.  How you will handle exceptions in Struts?
21.  Is Struts efficient?
22.  How you will enable front-end validation based on the xml in validation.xml?
23.  What is ActionServlet?
24.  How you will make available any Message Resources Definitions file to the Struts Framework Environment?
25.  What is Action Class?
26.  Can I setup Apache Struts to use multiple configuration files?
27.  How you will make available any Message Resources Definitions file to the Struts Framework Environment?
28.  What is Struts Flow?
29.  What is LookupDispatchAction?
30.  Write code of any Action Class?
31.  What is ActionForm?
32.  What is Struts Validator Framework?
33.  Give the Details of XML files used in Validator Framework?
34.  Why do we need Struts?
35.  How does Struts work?
36.  Is Struts compatible with other Java technologies?
37.  Who wrote Struts?
38.  Why is it called Struts?
39.  Do I have to credit Struts on my own website?
40.  Where can I get a copy of Struts?
41.  How do I install Struts?
42.  When do I need "struts.jar" on my classpath?
43.  Does Struts include its own unit tests?
44.  If the framework doesn't do what I want, can I request that a feature be added?
45.  Where can I get help with Struts?
46.  What's the difference between Struts and Turbine? What's the difference between Struts and Espresso?
47.  Why aren't the Struts tags maintained as part of the Jakarta Taglibs project ?
48.  Are the Struts tags XHTML compliant ?

Explain the use of the placement new method? | Constructor in C++

The placement new method is used to place an object at a particular location in memory. For placing an object to its particular location, it allocates a pointer parameter to a new part of a new expression.
 PROGRAM::
Line #1 creates an array of size of (Tom) bytes of memory, which is big enough to hold a Tom object. Line #2 creates a pointer place and points to the first byte of this memory. Line #3 essentially calls the constructor Tom::Tom (). The this pointer in the Tom constructor will be equal to place. The returned pointer j will therefore be equal to place.
 The sole responsibility of a programmer is to destruct the placed object. To do this, the explicit calling of the destructor is needed:
 void mno()
{
char memory[sizeof(tom)];
void* b = memory;
Bred* j = new(b) Tom();
j>~Tom();
e placed object
}
In the rare scenario like the preceding one, you need to explicitly call the destructor.

Can a destructor be explicit y called if an object is created using the new operator? | Constructor in C++

No, a destructor cannot be explicitly called if an object is created using the new operator. When you allocate the memory with the new operator, you are responsible for managing it yourself. To avoid cluttering up your program with memory that you are no longer using, you should delete it with the delete operator. The new operator returns a pointer to the newly allocated memory. Therefore, deleting the object is more prefe able than to call the destructor explicitly. For example, if you allocate the object via a typical new expression, such as:
Jerry* j = new ZJerryQ;
Then, the destructor Jerry: :~Jerry () will automatically get called on deleting it via:
delete j; //Automatically calls j->~3erry()
An explicit calling of the destructor would not release the memory that has been allocated for the Jerry object itself. The following are the two advantages of using the delete operator:
? It calls the destructor
? It deal locates the memory

What do you understand by zombie objects in C++? | Constructor in C++

In a situation, where an object is created in a class, a constructor fails before its full execution. It is very difficult to ensure about the execution of the constructor whether the constructor would return a value or not. Objects that are no more required for an application are called zombie objects. These zombie objects occupy a space in the memory and wait for their termination.

What are shallow and deep copies? | Constructor in C++

A shallow copy is used to copy actual values of the data. It means, if the pointer points to dynamically allocated memory, the new object's pointer in the copy still points to items inside the old objects and the returned object will be left pointing to items that are no longer in scope. A copy of the dynamically allocated objects is created with the help of a deep copy. This is done with the help of an assignment operator, which needs to be overloaded by the copy constructor.

What happens if the local variable cannot be wrapped in an artificial block? | Constructor in C++


Most of the times, the time duration of wrapping local variables is limited in an artificial block ({...}). In other situations, a member function with similar effects can be added as a destructor instead of calling the destructor itself.For example, in the case of class of Filel, a close() method can be added. Usually, the close() method can be simply called by the destructor. Note that there is a need of marking Filel by the close method(). It avoids the reclosing of an already closed file by a subsequent call of a destructor. For example, the value of the filelHandle can be set by the call of a destructor, such as -1 and the checking can be done at the beginning for ensuring that the filelHandle is already equal to value (-1):
PROGRAM::
Note that the other file methods may also need to check if the filelHandle_ is -1 (i.e., check if the Filel is closed).
Also note that any constructors that do not actually open a file should set filelHandle_ to -1.

Explain how would you handle a situation where you cannot call the destructor of a local explicitly? | Constructor in C++

To avoid the explicit calling of a destructor, the time extent of the local variable can be wrapped in an artificial block {...}:
void time()
{
{
copy c;
// ..insert code that should execute when c is still open..
}

What happens if a local variable is destroyed within its scope before a program is completely executed? Can a destructor be called if needed? | Constructor in C++

No, the destructor cannot be called if needed. Let's understand the preceding statement with the help of an example. There is a local variable n of a class Notebook. Now, the destruction of the local variable n occurs before the execution of a program:
Class Notebook
{
int n;
void bcd()
Notebook n;
// ..Insert code that should execute when n is still in it's scope..
we want the side-effect of n's destructor here!
// ..Insert code that should execute after n is destroyed..
}
On calling a destructor explicitly, an undefined behavior is occurred, because the destructor may invoke twice for the local variable. Firstly, on explicit calling and secondly automatic calling when the local variable destroys. Therefore, a destructor cannot be called explicitly if needed.

Can you explicitly call a destructor on a local variable? | Constructor in C++

No, the destructor is called when the block closes in which the local variable was created.
If a destructor is called explicitly twice on the same object, the result ends in an undefined behavior because the local variable gets destroyed when the scope ends.

Is it possible to overload the destructor of a class? | Constructor in C++

 No, the destructor of a class cannot be overloaded. We can have only one destructor for a class, called class name ::~ destructor name(). For example, for a class named fruit, the syntax is - fruit::~ fruit(). It never takes any parameters and it never returns anything.
We cannot pass parameters to the destructor anyway, since you never explicitly call a destructor.

Write about the sequence in which objects in an array are destructor?

The destructor is executed in the reverse order of constructor. Firstly, the objects are constructed, methods are invoked on them, and then they are destructed.
In the following example, 
the order for destructors will be b[19], b[18],b[17],b[16],b[15],b[14],b[13],b[12], b[ll], b[10]:
void def()
{
Bat b[20];
}

What is the sequence of destruction of local objects? | Constructor in C++

The destructor is executed in the reverse order of a constructor. Firstly, the objects are constructed, methods are invoked on them, and then they are destructed. In the following example, a's destructor will be executed after b's destructor.
void abc()
{
cat a;
cat b;
}

What is a virtual destructor? | Constructor in C++

 Virtual destructors help in destroying objects without knowing their type. With the help of the virtual function mechanism, the appropriate destructor for the object is invoked. In the case of abstract classes, destructors can also be declared as pure virtual functions. For example, class A derives from class B. Then, on calling the derived class dynamically at the execution time, the destructor will first call the derived class that is class A, and then the base class that is class B.
It is important to note that theVirtual keyword, when used with the destructor, ensures the calling of all the derived and base class destructors and therefore helps in the proper execution and closing of the program.

Define the process of handling in case of destructor failure? | Constructor in C++

In order to handle a failed destructor, you need to write a message to a log file; however, do not throw an exception. There is a rule in C++ that exception cannot be thrown from a destructor, which is called when the process of "stack unwinding" occurs in other exceptions. For example, if someone says throw waste files(), the stack frames between the throw waste files() and the catch (waste files) will get popped. This is known as stack unwinding. It is the process of destroying all the local objects related to those stack frames and calling destructors in case of throwing of an exception by one of those destructors. For example, if an object named Bar is thrown, then the C++ runtime system is in a neutral situation means either to avoid the Bar and end up in the catch (waste files) or ignore the function Foo and look for a catch (Bar) handler. It will call in the terminate () process to end the program.

What is a conversion operator? | Constructor in C++

 A conversion operator converts an object of a class in which you define the function to an object of a different data type. A conversion operator uses the C++ operator keyword in its declaration. C++ uses public as an access specifier, which can be used in a class as a public method for specific data type conversions.
Program:
In the preceding code snippet, operator double has no function assigned for the modification of the object/so it is better to make it constant.

Define a conversion constructor? | Constructor in C++

A conversion constructor is a single argument constructor. It is used by the compiler to convert a type of object as an argument to a class type.
Program:
The above example has the following two conversion constructors:
?Y(inti)— Helps in the conversion of integers to objects of class Y
?Y(const char* n, int j = 0) —Helps in the conversion of pointers from strings to objects of the Y class

Is it possible to pass an object of the same class in place of object reference to the copy constructor? | Constructor in C++

 Yes, when an object is created without the reference formal argument, then the copy constructor is called for the argument object. The object that is passed as a parameter to the function is then passed as a parameter to the copy constructor.
For example:
 void xyz(A);
A A1;
xyz(A1);
void xyz(A A2)
{
//definition of xyz()
}
In this case, the copy constructor is called for A2 while Al is passed as a parameter to the copy constructor.

When are copy constructors called? | Constructor in C++

A copy constructor is defined by the programmer or by compiler itself. A call to copy constructor is embedded under the following three conditions:
1. When an object is created and at the same time equated to some other existing object.
 For example:
A A1; //default constructor called.
A A2=A1; //copy constructor called.
(or)
A A2(A1) //copy constructor called.
(or)
A *Aptr= new A(A1); //copy constructor called.
2. When an object is created without having the reference of the argument, then the copy constructor is called by default for the argument object.
For example:
A A1;
xyz(A1);
void xyz(A A2)
{
//defination of xyz()
}
3. When an object is created and at the same time equated to a call to a function that returns an object.
For example:
A xyz();
{
A A1; //remaining defination of xyz();
return A1;
}
A A2=xyz();

What is a default constructor?

 A zero-argument constructor or a constructor in which all the arguments have default values is called a default Constructor.
For example:
A A1;    // default constructor called.

Explain the concept of copy constructor? | Constructor in C++

a Copy constructor is a special type of parameterized constructor. It copies one object to another. It is called when an object is created and equated to an existing object at the same time. An existing object is passed as a parameter to it.
For Example:
A A1; //default constructor called.
A A2=A1; //copy constructor called.
(or)
A A2(A1) //copy constructor called.
(or)
A *Aptr= new A(A1); //copy constructor called.

Define the process of error-handling in case of constructor failure? | Constructor in C++

If the constructor does not have the return statement, then it indicates failure in handling the error by throwing an exception.

Define two methods of constructor invocation? | Constructor in C++

The following are the two ways to invoke a constructor:
1. The compiler embeds a call to the constructor for each object that has got created. For example:
class A
{
int x;
public: void setx(const int=0);
int getx();
};
main()
{
A A1; //object declared constructor called.
A1.A(); //constructor called implicity.
}
2. The constructor is called for each object that is created dynamically in the heap by the new operator. For example:
A *Aptr
A*ptr=new A; //constructor called implicity by compiler.

How does a copy constructor differs from an overloaded assignment operator? | Constructor in C++

A copy constructor uses the value of an argument to construct a new object. We can use an overload assignment operator to assign the value of an existing object of the same class to another existing object in that class.

Can we declare a base-class destructor as virtual? | Constructor in C++

Yes, we can declare a base-class destructor as virtual that makes all derived-class destructors as virtual even if they do not have the same name as base-destructor. The problem arises when the derived class's pointer refers to a base class.
For this reason, the base class destructor should be declared as virtual so that the appropriate destructor is called on calling the delete method of the base class object.

Can we define a constructor as virtual in C++? | Constructor in C++

 No, we cannot define constructors as virtual because constructors have the same name as their classes and no two constructors of base-derived classes can have the same name. So, when we initialize an object of the base or derived class with the help of virtual constructors, the base constructor is invoked instead of the derived constructor. Therefore, it is not possible to define a constructor as virtual.

Define what is constructor? | Constructors in C++

A constructor is a method that is called when a new instance of an object of a class is created. It initializes all class members whenever you create an object of the class. It is a member function with the same name as its class. It may or may not take any parameters. It does not have any return type. For example, the compiler embeds a call to the constructor for each object when it is created. Suppose a class Z has been declared as follows:
class Z
{
public:
Z(); //Constructor for class Z
};
We cannot declare a constructor as virtual or static, nor we can declare a constructor as const, volatile, or const volatile.
The short form of constructor is ctor.

C++ Interview Questions and Answers for Freshers

1. What is C++?
2. What is a modifier in C++?
3. What is an accessor in C++?
4. Differentiate between a template class and class template in C++?
5. When does a name clash occur in C++?
6. Define namespace in C++?
7. What is the use of 'using' declaration in C++?
8. What is an Iterator class in C++?
9. What is an incomplete type in C++?
10. What is a dangling pointer in C++?
11. Differentiate between the message and method in C++?
12. What is an adaptor class or Wrapper class in C++?
13. What is a Null object in C++?
14. What is class invariant in C++?
15. What do you mean by Stack unwinding in C++?
16. Define precondition and post-condition to a member function in C++?
17. What are the conditions that have to be met for a condition to be an invariant of the class?
18. What are proxy objects in C++?
19. Name some pure object oriented languages?
20. What is a node class in C++?
21. What is an orthogonal base class in C++?
22. What is a container class? What are the types of container classes in C++?
23. How do you write a function that can reverse a linked-list in C++?
24. What is polymorphism in C++?
25. How do you find out if a linked-list has an end? (i.e. the list is not a cycle)
26. How can you tell what shell you are running on UNIX system?
27. What is Boyce Codd Normal form?
28. What is pure virtual function?
29. Write a Struct Time where integer m, h, s are its members
30. How do you traverse a Btree in Backward in-order?
31. What is the two main roles of Operating System?
32. In the derived class, which data member of the base class are visible?
33. How do you find out if a linked-list has an end? (i.e. the list is not a cycle)
34. What is the difference between realloc() and free()?
35. What is function overloading and operator overloading?
36. What is the difference between declaration and definition?
37. What are the advantages of inheritance in C++?
38. How do you write a function that can reverse a linked-list?
39. What do you mean by inline function?
40. Write a program that ask for user input from 5 to 9 then calculate the average?
41. Write a short code using C++ to print out all odd number from 1 to 100
42. What is public, protected, private in C++?
43. Write a function that swaps the values of two integers, using int* as the argument type.
44. Tell how to check whether a linked list is circular.
45. What is virtual constructors/destructors?
46. What is the difference between an ARRAY and a LIST?
47. Does C++ support multilevel and multiple inheritance?
48. What is a template in C++?
49. Define a constructor - What it is and how it might be called (2 methods).
50. You have two pairs: new() and delete() and another pair : alloc() and free().
51. What is the difference between class and structure in C++?
52. What is RTTI in C++?
53.What is encapsulation in C++?
54. What is a C++ object?
55. Describe PRIVATE, PROTECTED and PUBLIC - the differences and give examples.
56. What is C++ namespace?
57. What do you mean by inheritance?
58. What is a COPY CONSTRUCTOR and when is it called?
59. What is Boyce Codd Normal form in C++?
60. What is virtual class and friend class?
61. What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?
62. What do you mean by binding of data and functions?
63. What are 2 ways of exporting a function from a DLL?
64. What is the difference between an object and a class?
65. Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321].
66. What is a C++ class?
67. What is friend function in C++?
68. Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?
69. What is abstraction in C++?
70. What are virtual functions in C++?
71. What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator.
72. What is a scope resolution operator?
73. What do you mean by pure virtual functions?
74. What is polymorphism in C++? Explain with an example?
75. How can you quickly find the number of elements stored in a a) static array b) dynamic array ?
Why is it difficult to store linked list in an array?
76. What is the output of the following program? Why?
77. Why are arrays usually processed with for loop?
78. What is an HTML tag?
79.  Explain which of the following declarations will compile and what will be constant...
80. You are given a simple code for the class BankCustomer. Write the following functions ...
81. What problems might the following macro bring to the application?
82. Anything wrong with this code?
83. Anything wrong with this code?
84. How do you decide which integer type to use?
85. What is the best way to declare and define global variables?
86. What does extern mean in a function declaration?
87. What can I safely assume about the initial values of variables which are not explicitly initialized?
88. What is the difference between char a[] = "string"; and char *p = "string";?
89. What is the auto keyword good for in C++?
90. How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
91. What does extern mean in a function declaration in C++?
92. How do I initialize a pointer to a function?
93. How do you link a C++ program to C functions?
94. Explain the scope resolution operator.
95. What are the differences between a C++ struct and C++ class?
96. How many ways are there to initialize an int with a constant?
97. How does throwing and catching exceptions differ from using setjmp and longjmp?
98. What is a default constructor in C++?
99. What is a conversion constructor C++?
100. What is the difference between a copy constructor and an overloaded assignment operator?
101. When should you use multiple inheritance?
102. Explain the ISA and HASA class relationships. How would you implement each in a class design?
103. When is a template a better solution than a base class?
104. What is a mutable member?
105. What is an explicit constructor?
106. What is the Standard Template Library (STL)?
107. Describe run-time type identification.
108. What problem does the namespace feature solve?
109. Are there any new intrinsic (built-in) data types?
110. Will the following program execute?