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!
 
TL;DR Summary: I want to do a PhD in applied math but I hate group theory, is this a big problem? Hello, I am a second-year math and physics double major with a minor in data science. I just finished group theory (today actually), and it was my least favorite class in all of university so far. It doesn't interest me, and I am also very bad at it compared to other math courses I have done. The other courses I have done are calculus I-III, ODEs, Linear Algebra, and Prob/Stats. Is it a...
Yesterday, 9/5/2025, when I was surfing, I found an article The Schwarzschild solution contains three problems, which can be easily solved - Journal of King Saud University - Science ABUNDANCE ESTIMATION IN AN ARID ENVIRONMENT https://jksus.org/the-schwarzschild-solution-contains-three-problems-which-can-be-easily-solved/ that has the derivation of a line element as a corrected version of the Schwarzschild solution to Einstein’s field equation. This article's date received is 2022-11-15...
Back
Top