can somebody please guide me.......thanksF:\j2sdk1.4.0_03\bin>javac itemtype.java
itemtype.java:15: possible loss of precision
found : double
required: float
price = 5.00;
^
itemtype.java:26: cannot resolve symbol
symbol : constructor itemtype (java.lang.String)
location: class itemtype
products = new itemtype("shit");
^
2 errors
F:\j2sdk1.4.0_03\bin>
Is it possible to create an instance of itemtype without a constructor implemented?
Explain why for not; otherwise
my answer: No . it is because there would be nothing to take in the values.
That's true, if you don't implement a constructor, you can't pass any values in, but could you still create an itemtype object? How about this code:
Try compiling that and see what happens. Does it fail? Does it succeed? Why do you think it did what it did?
Okay, for now, let's go forward...
ii.Implement a constructor that takes necessary arguments for member variables to be initialized
my answer
You're awfully close. One thing to remember is that, when you perform an assignment, you assign the value of the variable on the right hand side to the variable on the left hand side. Do you see your mistake?
iii.Show you can overload the constructor by implementing another constructor in itemtype class.
my answer :
Okay, again you've got some of the same problems as above - look at what is being assigned to what. Think of it like this:
setThisVariable = toTheValueOfThisOne;
Now, let's look at the errors you're getting:
F:\j2sdk1.4.0_03\bin>javac itemtype.java
itemtype.java:15: possible loss of precision
found : double
required: float
price = 5.00;
^
itemtype.java:26: cannot resolve symbol
symbol : constructor itemtype (java.lang.String)
location: class itemtype
products = new itemtype("fruit");
^
2 errors
The first error is stating something about a loss of precision. The reason for this is that Java considers any decimal literal (in your case, 5.00) to be a double. A double doesn't fit into a float, so a compiler error is thrown. Try adding a 'f' to the end of the number, like this: 5.00f so that the compiler knows that you want that value to be a float, not a double.
The second error is because you're trying to invoke a constructor that takes just a String as a parameter. Do you have any of those? Hmmmm...
Try some of those things and come back with what you have.
Best of luck,
Corey
The second error is because you're trying to invoke a constructor that takes just a String as a parameter. Do you have any of those? Hmmmm...
i) it does compile w/o errors....but it does not do anything except create another object of itself ....rite??...what is the use of this???
(i see no use why someone would implement this..)
![]()
conclusion : i guess that an itemtype object can be created if a constructor is not implemented.
ii)
is this the proper way....??
i've tried to change the code but i got too many errors so i changed back..could you kinldy pls explain this in more detail...
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Tabrez:
ok Barry..its done....thanks for telling me...![]()
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Tabrez:
Yahoooo!!!thanks...you people r GREAT!!
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Barry Gaunt:
This is cooler:
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
No, tomorrow we rule the world! With this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
|