Preparing for AP Computer Science Test: Superclasses and Subclasses

AI Thread Summary
The discussion revolves around preparing for a Java test focused on superclasses and subclasses, particularly the free response section known as a "design question." Key points include the clarification that subclasses cannot inherit private instance variables from superclasses, and the importance of understanding inheritance principles. Good design in software engineering is emphasized, with advice on aligning classes with real-world objects, using the "is a" rule for inheritance, and the "has a" rule for composition. Recommendations for studying include practicing program design and reviewing class structures. Popular Java books mentioned are Deitel and Deitel, and "Head First Java" by Kathy Sierra and Bert Bates. Overall, the discussion encourages a solid grasp of object-oriented principles and practical application through programming exercises.
courtrigrad
Messages
1,236
Reaction score
2
Hello all

I need help with java. On Tuesday we will be having a test on superclasses and subclasses. There will be basic questions such as: Can a subclass inherit from a superclass's private instance variables? The answer is no. However, I really need to work on the free response section my teacher will be giving. It is called a "design question." Can anyone give any advice as to what the best way is for studying for the free response? Has anyone ever heard of a "design question?" Also, what are the best Java books out on the market (heard Deitel and Deitel is pretty good)

Any advice is greatly appreciated.

Thanks!
 
Physics news on Phys.org
courtrigrad said:
Hello all

I need help with java. On Tuesday we will be having a test on superclasses and subclasses. There will be basic questions such as: Can a subclass inherit from a superclass's private instance variables?

That doesn't quite make sense. Are you sure the question wasn't can a subclass access a superclasses private instance variables? The answer would be no.

However, I really need to work on the free response section my teacher will be giving. It is called a "design question." Can anyone give any advice as to what the best way is for studying for the free response? Has anyone ever heard of a "design question?" Also, what are the best Java books out on the market (heard Deitel and Deitel is pretty good)

Good design is in software engineering is pretty hard and really only comes with experience, but there are a few general principles that one should abide by when following an object oriented methodology. The first principle is that your classes should correspond as close as they can to real world objects, or understandable "virtual" objects. This is not always possible or useful, but it is a good principle to follow. In a similar vein, your objects should also be well named. For example if I am doing a racing simulation, I would probably have a class called "Vehicle" which corresponds to and models everything I want about the vehicles I am going to model. I would then have subclasses with particular types of vehicles to model.

Follow the 'is a" rule for inheritance. In other words if you can't say that a subclass "is a" type of the superclass, then don't inherit. An example would be that a "Truck" is a "Vehicle" in our racing simulation. On the other hand, I may not need several layers of subclasses if I cannot justify it. For instance, I could have something like Vehicle->Truck->Pickup->Ford 150, but is there really a need for the Truck and Pickup sublclasses? Do all trucks have enough in common that I can do something meantful at that level that will be used by all subclasses?

Follow the "has a" rule for containership. If class A has another class B as a instance variable. you should be able to say that the class A "has a" class B. For example, suppose I want to model the engine of the car. I would probalby have another class called "Engine" that would model the engine, and put it as an instance variable in my class "Vehicle", because all Vehicles have Engines.

Public instance variables should never be used. Use accessor functions instead. Many people think this is unwieldy but it is a good design principle.

Static class methods should rarely be used.

Functions should be simple and accomplish small, but meaningful tasks. For example, I might have some function called vehicle.start() which starts the car running. Yes, it might only be a few lines of code but it has accomplishes a definite, easily understandable goal. I would not want a funciton like vehicle.simulate() which does everything. That would probably go in some other class which manages the entire simulation. A good principle to follow is that you have any more than 10 if, else, for, or switch statements, you probably need to start a new function or come up with some different classes.

If you want to take a look at good design, Sun's Swing toolkit isn't bad. Its fairly complex but believe me its a lot simpler than a lot of GUI's out there.

I'm not sure about books, I actually never took a software engineering class in college, and know enough about languages that I can read the documentation and language specfication and figure out everything for myself. O'Reilly books tend to be well written. It seems like the shorter the book, the more useful it is. Avoid anything like Java in 21 days, Java for dummies, etc. Knuth's books would probably be a bit too advanced for you but you can check them out if you're up for a real challenge.
 



Hi there,

I can offer some tips for studying for the free response section of the AP Computer Science test. Firstly, it's important to understand the concept of inheritance and how superclasses and subclasses relate to each other. Make sure you have a solid understanding of the syntax and how to properly declare and use subclasses.

As for the "design question," this is likely a question that requires you to use your knowledge of superclasses and subclasses to design a program or class structure. My advice would be to practice creating your own programs and classes using inheritance to get comfortable with this concept. Also, review any practice questions or assignments your teacher has given you to get a better idea of what to expect.

In terms of Java books, Deitel and Deitel is a popular and highly recommended choice. Another good option is "Head First Java" by Kathy Sierra and Bert Bates. It's important to find a book that works for your learning style, so don't be afraid to try a few different ones.

Good luck on your test! With some practice and a solid understanding of the material, I'm sure you will do well. Don't hesitate to ask your teacher for clarification or extra help if needed. Keep up the good work!
 
Bit Britain-specific but I was wondering, what's the best path to take for A-Levels out of the following (I know Y10 seems a bit early to be thinking about A-levels, but my choice will impact what I do this year/ in y11) I (almost) definitely want to do physics at University - so keep that in mind... The subjects that I'm almost definitely going to take are Maths, Further Maths and Physics, and I'm taking a fast track programme which means that I'll be taking AS computer science at the end...
After a year of thought, I decided to adjust my ratio for applying the US/EU(+UK) schools. I mostly focused on the US schools before, but things are getting complex and I found out that Europe is also a good place to study. I found some institutes that have professors with similar interests. But gaining the information is much harder than US schools (like you have to contact professors in advance etc). For your information, I have B.S. in engineering (low GPA: 3.2/4.0) in Asia - one SCI...
I graduated with a BSc in Physics in 2020. Since there were limited opportunities in my country (mostly teaching), I decided to improve my programming skills and began working in IT, first as a software engineer and later as a quality assurance engineer, where I’ve now spent about 3 years. While this career path has provided financial stability, I’ve realized that my excitement and passion aren’t really there, unlike what I felt when studying or doing research in physics. Working in IT...
Back
Top