Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java 1. Assume that we have defined a class named MyClass. MyClass has a default constructor. Please write the code snippet to declare a

In Java

1. Assume that we have defined a class named MyClass. MyClass has a default constructor. Please write the code snippet to declare a variable called myClass1 and assign a new object to it.

2. Write a class named MyClass with the following members:

a private instance variable of double type called "value";

a default constructor that give a default value 0 to the variable "value";

a parameterized constructor that assign a parameter to the "value" instance variable as its initial value;

3. Write a class called Coordinates with:

1. two instance variables: x and y as double

2. a default constructor that initialize x and y as 0

3. corresponding mutators and accessors for both x and y

4. Assume that we have a class called MyClass. MyClass has a (non-static) method called giveMeAValue() that will give an arbitrary integer value when called. Assume that we have created an object named myClass1 of the MyClass type.

Write the code to print a line of text to the screen like:

I have a value which is XX!

Replace XX with the value that the giveMeAValue will return.

5. State whether the following are primitive types or reference types:

-double

-string

-char

-integer

-scanner

-int

6. Assume we have a method called in the main method like this:

System.out.printf("The num or words is %d.", numOfWords(text));

Please write the definition line (aka, signature of method, first line of a method definition) of the method numOfWords. Make the best guess of the types.

Hint: static or non-static?

7. Please check correct statements about wrapper classes.

Question 7 options:

- Some advanced Java data structures only works with objects so wrapper classes have to be used to replace the - primitive types.

- Wrapper class can carry useful methods related to the corresponding wrapper class.

- To check if two wrapper class variables has same values, you should use .equals() or .compareTo() rather than ==

- Wrapper class variables can be used in most expressions same way as their primitive type counterparts.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

Write down the circumstances in which you led.

Answered: 1 week ago