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

Which of the following statements will convert a string s into a double value d?

ID: 3582892 • Letter: W

Question

Which of the following statements will convert a string s into a double value d? d = (new Double(s)).doubleValue(); d = Double.parseDouble(s); d = Double.valueOf(s).doubleValue(); All of the above. You can declare two variables with the same name in. different methods in a class two nested blocks in a method (two nested blocks means one being inside the other) a block a method one as a formal parameter and the other as a local variable An aggregation relationship is usually represented as in a data field/the aggregating class a data field/the aggregated class a method/the aggregated class a method/the aggregating class which of the following statements are correct? new java.math.Biglnteger("343"); new java.math.Biglnteger(343); new java.math.BigDecimal("34 3.445"); new java.math.BigDecimal(343.445); A class design requires that a particular member variable must be accessible by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this? The variable should be marked public. The variable should be marked private and an accessor method provided. The variable should be marked private. The variable should be marked protected. The variable should have no special access modifier.

Explanation / Answer

17 answer)

convert String to Double using one of the following ways.

  Double dObj1 = new Double("1000.564");

  System.out.println(dObj1);

2. Use valueOf method of Double class. This method is static.

  Example:

    String str1 = "100.476";

  Double dObj2 = Double.valueOf(str11);

  System.out.println(dObj2);

3.To convert a String object to a double primitive value parseDouble method

of Double class. This is a static method.

Example:

  String str12= "761.39";

  double d1 = Double.parseDouble(str12);

  System.out.println(d1);

From that clearly option d is correct(all of the above)

18 answer)

You can declare two variables with the same name in different methods in same class

Example:

Public class Hi

{

Method1(){

Int a;

}

Method2()

{

Int a;

}

}

19)

An aggregation relationship is usually represented as a data field in the aggregating class

20)

new java.math.BigInteger("343");

new java.math.BigDecimal("343.445");

this two are correct because first one 343 is integer so correct declaration.

Second one 343.445 is decimal so correct declaration.

21)

A class design requires that a particular member variable must be accessible by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this?

Answer:

The variable should be marked protected.

protected access modifier :

1)It is accessible within package and outside the package but through inheritance only.

2)    It can be applied on the data member, method and constructor.

It can't be applied on the class.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote