Discussions
Categories
- 196.9K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 545 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.6K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 440 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
abstract method in lab 4?

Hi Nick,
I have 2 more questions regarding lab 4. I guess I don't quite comprehend your code.
1) In "Account.java"
public abstract String getAccountType();
Is above line of code "getAccounType()" an abstract method you mentioned in the video/slides?
If it is, what's the point of declare a method without performing any function?
2) In both "CheckingAccount.java" and "SavingsAccount.java"
What's the point of declare "getAccountType()" method in abstract Account class when both CheckingAccount and SavingsAccount declare their own method without using "super" keyword?
public String getAccountType() {
return accountType;
};
Thanks,
Carol
Answers
-
Hi Carol,
These are such amazing questions! I was hoping someone would pick up on this. You've come so far since the beginning of the course! Both questions share the same answer.
Yes, getAccountType() in the Account class is an abstract method. Abstract methods may only exist in abstract classes. They have no implementation and must be implemented later by any non-abstract (known as "concrete") sub classes. I thought I should write this method in the Account class because of how the ArrayList stream works. accountList contains only accounts. If you create a stream and use the dot operator on an account instance, you can only access the public fields and methods written in the Account class. That is, unless you resort to casting like in button6Pressed(). I thought it would be unfair and messy to make people cast, because we didn't really cover that technique. So to avoid casting, I wrote getAccountType() in the Account class. The implementation which gets used depends on whether the account is a Savings or a Checking account. It's a sneaky way of taking advantage of polymorphism.
Nick
-
What you said is very interesting Nick!!! I'd like to learn casting then. I've always curious about Java. However I got into this course without knowing if I could make it out alive. I ended up really enjoy it. The GUI banking application is really fun stuff too...The lab project is something everyone can relate to. It was brilliant to learn Java programming by playing around. It would be really cool if there were more games and courses like this.
1) I'd love to finish playing those fun games which some of them I didn't have the chance to do yet. I understand this discussion forum may discontinue after June 1. Can I still ask questions here?
2) This is the first online course I take from Oracle. When I tried to follow your instruction regarding new way of accessing course page, I was shocked to see "I am a oll user since 2013" under my name!?
3) Is there another free course from Oracle to advance my knowledge in Java programming?
Thanks,
Carol
-
I would LOVE to create more game-based learning courses like this! The tricky part is convincing Oracle it's worthwhile. Although games can be a tremendously powerful way to learn, they take a while to develop and are unfamiliar territory for the corporate world. Ha ha, so you're welcome to help me lobby. How would you feel about sending your thoughts about the course to the mailing list ([email protected])? That list goes to me and a couple higher-ups who I'd like to convince that game-based learning should be a priority.
1) We'll keep the forum active after June 1. But it will be a lot harder for me to answer questions as frequently as before.
2) Have you had an OTN account since 2013? I believe the logins between the OLL and OTN are shared. If not, you might have found a bug,
3) I highly recommend Oracle Academy Java Foundations. I wrote that course to be just as playful and explorative as the Java Puzzle Ball MOOC. Membership with Oracle Academy is free, as long as you're associated with some sort of educational institution. There's also a free JDK 8 Lambda MOOC created by Simon Ritter available on the Oracle Learning Library. That course is more advanced and dives a lot deeper into Lambda and Streams. One last option is convincing your employer to pay for training through Oracle University Java SE 8 Fundamentals. Oracle University targets corporate customers.
Nick
-
Of course I'll help you lobby Nick since I have positive learning curve from this course. Let me think about what to say to help you achieve your aspiration. I aim to send my message before June 1. .
1) Thanks for keeping the forum active. I understand you have to move on to your next project at work, so it's expected that answering questions here would become a low priority for you after June 1. If I could hurry myself up to take quiz 4 before official course end date 25th May, I probably can speed up finishing game too. I'll start doing it tomorrow.
2) What's OTN? What does it stand for? I had a giggle after seeing something I didn't know about myself
3) I bumped into this course through a junk email. I didn't know Oracle has online learning course before receiving that junk email. I thought Oracle is all about Oracle database, so this Java course was a pleasant surprise. I'm currently not a student. Does that mean I'm not eligible for membership with Oracle Academy? I didn't do well on quiz 4. Will I have trouble to understand Simon Ritter's advanced course based on my limited basic Java knowledge?
Hmm...I'm lost about how to re-build my IT career after years away...Housing is expensive at where I live and drain away my savings...So I need to go for free courses.
4) Is abstract class a super class?
Carol
-
Thanks! Yes, your experience and growth with the course is a remarkable story.
1) Good luck!
2) OTN stands for Oracle Technical Network. The forum is a part of OTN.
3) Oh, interesting to hear about the email. I was wondering how Oracle ended up promoting the course. You wouldn't necessarily need to be a student to get an Oracle Academy membership. I believe it's also possible to join as an instructor or if you're on a school's advisory committee. I wonder if alumni qualifies? I'll try to think of other options. I think the first lesson of Simon's lambda course might be doable. But the next two get harder.
4) Correct, the Bumper and Account classes are both abstract and super classes. In fact, I think an abstract class would have be a super class in order to be useful. Since instances of an abstract class can't be created, an abstract class would need to be extended by a subclass at some point.
Nick
-
In light of you moving on to other projects soon, I'd like to ask this question today. Is it ok to re-visit question 2 regarding using super keyword?
I understand polymorphism allows sub class to inherit methods from super class as well as to have additional methods which aren't found in the super class. On page 13 of the slides for lesson 3-3, you mentioned using "super" keyword to call methods from super class. Since abstract class Account is also considered as a super class, Maybe I have a fuzzy head, it just looks like the abstract method getAccountType() in Account.java is not necessary at all because getAccountType() in CheckingAccount.java and SavingsAccount.java can be seemed as the additional method which aren't found in the super class "Account". Do you understand what I'm trying to say?
Or is super keyword only used when there's a need to pass parameters? Using "super" keyword in lab 4 would probably cause logic error because there's no implementation in method getAccountType() in super class Account. Well do you understand the confusion in my head?
I hesitate to raise this confusion in my head when you first answered my question. By the way, I've sent in the support message to the group email you told me.
Carol
-
Yes. It is possible to write the program so that the abstract getAccountType() method is omitted from the Account class. It just means doing a little casting whenever you want to call that method on an Account ArrayList object. Abstract methods are a design option programmers have available to them. People often use the analogy of a "contract" to describe abstract methods. Abstract methods mandate that all potential sub classes promise to provide their own implementation for the method. By writing getAcountType() as an abstract method in the Account class, it forces all potential sub classes to provide their own implementation. I didn't think I could provide an implementation in the Account class because it would rely on retrieving a static field variable which didn't yet exist.
You're right. In fact, NetBeans won't even allow sub classes to call super.getAccountType(), since the abstract method getAccountType() doesn't have an implementation. Sometimes it's useful to call a super class's version of a method so you can pass values to it. Other times, you do it to reuse the same logic found in the super class's version of the method. For example, calling super.printDetails() in the printDetails() method of the CheckingAccount class is a way to reuse the same printout logic.
I saw. Thank you, thank you! That was a such a nicely written letter.
Nick