Skip to content

Tag Archives: Constructors

In general, creating a copy of an object means to create an exact replica of the object having the same literal value, data type, and… Read More
In Object Oriented Programming, Objects are the instances of a class which has its own state(variables) and behavior(methods). Every class has two special methods related… Read More
Prerequisites: l-value and r-value references in C++, Copy Constructor in C++. What is a Move Constructor?   The copy constructors in C++ work with the… Read More
We use new and delete operators in C++ to dynamically allocate memory whereas malloc() and free() functions are also used for the same purpose in… Read More
class Test {     static int a;            static     {         a = 4;         System.out.println ("inside static block\n");         System.out.println ("a = " + a);     }            Test()… Read More
final class Complex {     private  double re,  im;     public Complex(double re, double im) {         this.re = re;         this.im = im;     }     Complex(Complex c)     {       System.out.println("Copy… Read More
Output of following Java program class Point {   int m_x, m_y;        public Point(int x, int y) { m_x = x; m_y = y; }… Read More
Is there any compiler error in the below Java program? class Point {     int m_x, m_y;      public Point(int x, int y) {    m_x = x;   … Read More
Which of the following is/are true about constructors in Java? 1) Constructor name should be same as class name. 2) If you don't define a… Read More
Predict the output of following Java program class T {   int t = 20;   T() {     t = 40;   } } class Main {    public… Read More
Predict the output? package main; class T {   int t = 20; } class Main {    public static void main(String args[]) {       T t1 =… Read More
#include<iostream> using namespace std;    class Test { public:    Test(Test &t) { }    Test()        { } };    Test fun() {     cout << "fun() Called\n";… Read More
Predict the output of following program? #include <iostream> using namespace std; class Test { private:     int x; public:     Test(int i)     {         x = i;         cout… Read More
#include<iostream> using namespace std;     class Test { public:   Test(); };     Test::Test()  {     cout << " Constructor Called. "; }     void fun() {… Read More
Which of the following is true about constructors. 1) They cannot be virtual. 2) They cannot be private. 3) They are automatically called by new… Read More