Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer the following questions are question relating to java. 1. Declare

ID: 3694624 • Letter: P

Question

Please answer the following questions are question relating to java.

1. Declare a string variable: String s1 = new String(“hello”); Will the following two statements return true or false? Why?

s1.equals(“hello”)

s1 == “hello”

2. What’s the difference between non-static method and static method?

3. About argument promotion and casting, what’s the promotion rule?

4. When and why do we need a Random object with a seed value?

5. What is Shadowing in Scope of Declaration? How to call shadowed variable in the main method?

6. What is method overloading?

Explanation / Answer

1. true

2. Static variable is class variable. it will be same for all the objects of the class. for different2 object , it will not be different. It is accessed by class not by object.
Non static variable is different for all the object. it is accessed by object of the class.

3. One conversion context is the operand of a numeric operator such as + or *. The conversion process for such operands is called numeric promotion. Promotion is special in that, in the case of binary operators, the conversion chosen for one operand may depend in part on the type of the other operand expression.

4. The seed is the initial value of the internal state of the pseudorandom number generator which is maintained by method next(int).

5. The basic purpose of shadowing is to decouple the local code from the surrounding class. If it wasn't available, then consider the following case.

A Class Foo in an API is released. In your code you subclass it, and in your subclass use a variable called bar. Then Foo releases an update and adds a protected variable called Bar to its class.

Now you class won't run because of a conflict you could not anticipate.

However, don't do this on purpose. Only let this happen when you really don't care about what is happening outside the scope.

6. Method Overloading is a feature that allows a class to have two or more methods having same name, if their argument lists are different.
my that we can use same name function with different argument.