Why we need new operator in java at the time of object
declaration and why not in c++?

Answer Posted / anuja joshi

The major difference between Java and C++ is the behavior of object variables. In C++, object variables hold values, not object references. Note that the new operator is never used when constructing objects in C++. You simply supply the construction parameters after the variable name.

Point p(1, 2); /* construct p */

If you do not supply construction parameters, then the object is constructed with the default constructor.

Time now; /* construct now with Time::Time() */

This is very different from Java. In Java, this command would merely create an uninitialized reference. In C++, it constructs an actual object.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a function which accepts a sentence as input parameter.Each word in that sentence is to be reversed. Space should be there between each words.Return the sentence with reversed words to main function and produce the required output. for eg:- i/p: jack jill jung kill o/p: kcaj llij gnuj llik

2087


What is the difference between COM and CORBA?

916


As per interoperatbility programs written in one language can be used by other language. How can we restrict the features of one language (say C#) in the programmer written in another language (say VB)..for example we have some features like operator overloading which is possible C#.NET (not in VB.NET), how can we restrict that when we are using this code in VB.NET.

1706


Do not use more than 3 nested IF. Use Evaluate statement in case of more IF required. Please give a detail explantion besides readability and clarity for Evaluate stmt.

1728


how can we implement locks in plsql?

2047


What is dialog programming?

1770


HOW TO FIND NUMBER OF TWOS IN N!(N FACTORIAL)??

1998


what is delegate and how works delegate and event.

1964


there are N number of matchboxes numbered 1...N.each matchbox contain various number of stick.Two player can alternatevely pick some amount of stick from the higest stick containing box . The player is condidered win if there is no stick after his move.Find the final move so that the move player win. Note:In case the number of stick is equal ,pick the stick from the higest numbered box. eg: 3 box contain stick as:1,1,1. if u take 1 stick from 3rd numbred box you will any how win the match.

2621


For a binary tree with n nodes, How many nodes are there which has got both a parent and a child?

3417


I am looking for NIC Sample papers or any patern of questions/ syllabus plz, send me on hamid.khan135@yahoo.in Regard

1735


the systematic access of small computers in a distributed data processing system is referred as?

2963


how to fin top two miximum values in sql? not 2nd both max value of 1st and 2nd both have to find out

1693


A good website has the following conditions It should be interactive. It should contain at least 20 images. Title cannot be null and should contain at least 10 letters other than spaces and hyphen (-). The keywords should contain atleast three among the following list : "design", "Graphics", "lovely", "beautiful", "amazing" and "mesmerising" Write a method: boolean isGoodWebsite(boolean isInteractive, int numOfImages, String title,String keywords[]) isInteractive whether the site is interactive or not numOfImages Number of images on the website title Title of the website keywords Array of keywords in the website.

2019


any drawback are there in mantis?

1861