Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
at pet.Pet.<init>(Pet.java:15)
at pet.PetDemo.main(PetDemo.java:155)
C:\Users\Violettwilight\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Being Java programmer.
Being Java programmer.
Yes I think OP didn't consider other animals. It would be easy if we create a separate class named Pet which will have these fields String petName, int petAge, float petWeight and String petType.Campbell Ritchie wrote:Agree about braces but not about the field speciesDog. You are going to create dreadful spaghetti code if you try all those fields. What about cats, and calculating the dose of morphine? You will have to think again about different dosages for different species.
Being Java programmer.
Maybe. But surely you are better off having an abstract Pet class and subclasses Dog, Cat, etc etc.Ganish Patil wrote:. . . It would be easy if we create a separate class named Pet which will have these fields String petName, int petAge, float petWeight and String petType.
Ohh I see, you mean declare common fields of Pets in Pet abstract class. Common behaviours of Pets comes in Pet abstract class like (Just assumed) sleeping(), drinkingWater() as defined methods of Pet abstract class whose implementation we know and methods (behaviour) which are type specific like makeNoise() where Dog barks and Cat meows so their implementation will be in respective classes i.e. type specific. Means when we know partial implementation then go for abstract class and when have no idea of implementation then go for interface, hope I'm correct?Campbell Ritchie wrote:Maybe. But surely you are better off having an abstract Pet class and subclasses Dog, Cat, etc etc.
Being Java programmer.
Yes helped a lot, Wiki is really a great source of information, I better peruse them. Thank youCampbell Ritchie wrote:I hope that will help
Being Java programmer.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |