Question

3) Compare C++ and Java: C++ uses destructors. Why does Java have no destructors? A C++...

  1. 3) Compare C++ and Java:

    1. C++ uses destructors. Why does Java have no destructors?

    2. A C++ constructor must call its superclass constructor using the superclass name. A Java constructor can use the super keyword to call the superclass constructor. Why is C++ not able to use the super keyword for this purpose?

    3. In C++, is circle1 a pointer or instance after this declaration: Circle circle1;

    4. In C++, is circle1 a pointer or instance after this declaration: Circle * circle1;

    5. In Java, is circle1 a pointer or instance after this declaration: Circle circle1;

    6. If circle1 is a pointer, what line of code would cause it to point to an new instance? Write the line of code in both C++ and Java.

      C++: Java:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ uses destructors. Why does Java have no destructors?

In c++, garbage collection is programmer overhead, programmer manually has to deallocate memory, release all the memory reference.Destructor does all the work in c++. that's why it is important

But in Java, garbage collection is done by JVM, programmer does not have to worry about deallocating the memory etc.

That's why destructor is not used in java

A C++ constructor must call its superclass constructor using the superclass name. A Java constructor can use the super keyword to call the superclass constructor. Why is C++ not able to use the super keyword for this purpose?

C++ supports multiple inheritances, which means it can inherit more than one class at the same time.

when super is used to call parent class constructor it will call immediate parent class. but one c++ class can have more than one parent class. so using super can be very confusing here, that's why C++ constructor must call its superclass constructor using the superclass name

But Java does not support multiple inheritances, only one immediate parent class so using super is safe

In C++, is circle1 a pointer or instance after this declaration: Circle circle1; circle1 is an instance of class circle

In C++, is circle1 a pointer or instance after this declaration: Circle * circle1: circle1 is pointer to class Circle

In Java, is circle1 a pointer or instance after this declaration: Circle circle1: circle1 is an instance of the class Circle

If circle1 is a pointer, what line of code would cause it to point to an new instance? c++

Circle * circle1; // pointer to class Circle

Circle circle2 //instance

Circle circle3 //instance

circle1=&circle2 //pointer pointing to instance circle2

circle1=&circle3 //pointer pointing to instance circle3

In Java

There is no such thing as pointer

Add a comment
Know the answer?
Add Answer to:
3) Compare C++ and Java: C++ uses destructors. Why does Java have no destructors? A C++...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java Which of the following statements declares Salaried as a subclass of payType? Public class...

    In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...

  • Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...

    Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance variables x and y that represented for the coordinates for a point. Provide constructor for initialising two instance variables. Provide set and get methods for each instance variable, Provide toString method to return formatted string for a point coordinates. 2. Create class Circle, its inheritance from Point. Provide a integer private radius instance variable. Provide constructor to initialise the center coordinates and radius for...

  • Java True or false: The code shown on line 9 of the DividendStock class, super(symbol) illustrated...

    Java True or false: The code shown on line 9 of the DividendStock class, super(symbol) illustrated how a subclass can call its parents constructor. call Stock's getProtit method a methods share the same name, call stock's version. Again, you do this using the n have DividendStocks ger of its computation. However, since the two ant to you must explicitly tell the compiler that you w Here is the corrected code, which does compile and elma super keyword. redundancy / returns...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • Q 4(b) 6 Marks] Write the code for a single Java class of your own choice that demonstrates the use of the following features in the Java language: Method overloadingg The use of super and this Ident...

    Q 4(b) 6 Marks] Write the code for a single Java class of your own choice that demonstrates the use of the following features in the Java language: Method overloadingg The use of super and this Identify clearly where in your code each of these points is being demonstrated Q 4(c) [6 Marks] Write an abstract Student class in Java which has a name, id_number, year and programme_code as member variables. Add a constructor to your class and a display()...

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • (C++ exercise) 5. Write a new Checkbook class that uses a dynamic array. Call the class...

    (C++ exercise) 5. Write a new Checkbook class that uses a dynamic array. Call the class a different name, since it will be different from the latest version that uses a static array. Start off with a dynamic array size of 2, made by the constructor. Every time the dynamic array becomes full and a new check has to be written, double the current size of the array. Write a doubleArray function for the class to do this, but place...

  • Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables...

    Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables and 2 effectors for a new data type – the class HospitalPatient. You have the freedom to design the instance variables and effectors. instance variables effectors 1. 1. 2. 2. 3. Write the code for class HospitalPatient, according to the requirement above. Include the default constructors with no argument, and the constructor with all arguments. Provide a getter and setter for each individual instance...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT