Monday, October 18, 2010

Questions On Java Object creation

Q Can classes inherit from more than one class?

It's possible with some programming languages but not Java. Multiple inheritance is a powerful feature, but it also makes object-oriented programming a bit harder to use and to learn. Java's developers decided to limit inheritance to one superclass for any class, although a class can have numerous subclasses.

Q Why are object-oriented programs easier to debug?

Object-oriented programs enable you to focus on a smaller part of a computer program when figuring out where an error is happening. Because a related group of tasks are handled by the same object, you can focus on that object if the tasks aren't being performed correctly. You don't have to worry about any other parts of the program.

Q When would you want to create a class that isn't public?

The main time you would not want to make a class of objects available to other
programs is when the class is strictly for the use of one program you're writing. If you're creating a game program and your
ReloadGun class of objects is highly specific to the game you're writing, it could be a private class. To make a class private, leave off the public statement in front of class.
The following questions will test your knowledge of objects and the programs that use them.
1. What statement is used to enable one class to inherit from another class?


Why are compiled Java programs saved with the
.class file extension?

(a) Java's developers think it's a classy language.
(b) It's a subtle tribute to the world's teachers.
(c) Every Java program is a class.

What are the two things that make up an object?

(a) attributes and behavior
(b) commands and data files
(c) spit and vinegar
1. b. The extends statement is used because the subclass is an extension of the attributes and behavior of the superclass and of any superclasses above that in the class hierarchy.

c. Your programs will always be made up of at least one main class and any other classes that are needed.

a. In a way, b is also true because commands are comparable to behavior, and data files are analogous to attributes.

1 comment: