Hi Guys, In below code you can see that i am able to execute the functionality of class a , inside the class b through composition and object of b can be used to call the methods declared inside the a class. #include <iostream> using namespace std; class a { int a1; public: a( int _a1=0):a1(_a1) { } void showname() { cout<<"class name a with value ="<<a1<<endl; } }; class b { public: b(a* cobj) : cobj(cobj) { cout<<"object initialization\n"; } void display() { cobj->showname(); } ~b () { cout<<"deleted the object of a"<<endl; delete cobj; } private: a *cobj; …

Member Avatar
Member Avatar
+0 forum 14

Line2D Points is made up of Point2D x and y Line2D.h [code] #ifndef LINE2D__H #define LINE2D__H #include <iostream> #include <fstream> #include <string.h> #include <ostream> #include <sstream> #include <cstdio> #include <vector> #include <set> #include <cstdlib> #include <ctype.h> #include "Point2D.h" using namespace std; class Line2D { friend ostream& operator<<(ostream&, const Line2D&); private: //Declarations Point2D pt1; Point2D pt2; protected: //Declarations double length; //Functions void setLength(); public: //Constructor Line2D(); Line2D(Point2D,Point2D); //Get Methods Point2D getPt1(); Point2D getPt2(); double getScalarValue(); //Set Methods void setPt1(Point2D); void setPt2(Point2D); }; #endif [/code] Line2D.cpp [code] #include <iostream> #include <fstream> #include <ostream> #include <iomanip> #include <string.h> #include <sstream> #include <cstdio> #include …

Member Avatar
Member Avatar
+0 forum 8

Hi guys. I am hoping for a little help with this. I am pretty new to programming and just can't seem to get things right yet. Here is my code. It returns like 40 errors. Way messed up eh? [CODE]#include <iostream> #include <string> using namespace std; class Date { public: Date(); //default constructor Date(int month, int day, int year); //constructor with parameters void setMonth(int); void setDay(int); void setYear(int); int getMonth(); int getDay(); int getYear(); void printDate(); private: int month; int day; int year; }; class Time { public: Time(); //constructor Time(int, int); //constructor with parameters void setHour(int); void setMinute(int); int …

Member Avatar
Member Avatar
+0 forum 4

[CODE]class A extends B { C ob1=new C(); D ob2=new D(); protected void finalize() { System.out.println("Finalizing A"); super.finalize(); } public static void main(String ss[]) { new A(); System.gc(); } }[/CODE] Though System,gc() doesn't guarantee the running of finalization, my question is if the JVM is able to run the finalizations at the time of call to gc(), what will be the order of execution of the finalizations for the classes A,B,C,D (assuming that all have finalizations with a code similar to that of A's and that apart from A, none of the classes explicitly inherit).

Member Avatar
Member Avatar
+0 forum 9

The End.