3) Compare C++ and Java:
C++ uses destructors. Why does Java have no destructors?
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?
In C++, is circle1 a pointer or instance after this declaration: Circle circle1;
In C++, is circle1 a pointer or instance after this declaration: Circle * circle1;
In Java, is circle1 a pointer or instance after this declaration: Circle circle1;
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:
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
3) Compare C++ and Java: C++ uses destructors. Why does Java have no destructors? A C++...
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 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 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 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...
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++
Part 1, c. Match each of the vocabulary words at the right with the BEST definition on the left. This operator is shorthand for adding a value to something ✓ Choose... This keyword is used to de-allocate memory allocated with the new operator. protected exit The increment operator for C++ This method is used to "Clean up" when an object is deleted. private Destructor Operator When you are accessing a method through a pointer, you can use this operator...
I need help for part B and C
1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...
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...
Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...
(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...