Skip to main content

Any Java Source for 16 Questions

1 reply [Last post]
firsttimer
Offline
Joined: 2006-03-10
Points: 0

I have been assigned to complete 45 questions using any Java source avaialble. I have found all except 16 of them in my Java book. This source was mentioned by the instructor as available. Could you please spend a minute to T or F them?

1. T or F. Static methods must be declared before dynamic methods in a class.

2. T or F. Static methods can access static variables of a class, but instance methods cannot.

3. T or F. You can override instance methods in a subclass.

4. T or F. If b is of class B and doit() is an instance method defined in B, then b.doit() always refers to the doit() from class B.

5. T or F. Static methods cannot access the private instance variables of of an object, but they can access the public instance variables.

6. T or F. More than one class can exist in a file, but classes cannot be nested.

7. T or F. Instance variables can be initialized when they are declared.

8. T or F. Local variables do not have an initial value by default.

9. T or F. A Java class can inherit from two unrelated classes.

10. T or F. A Java class can implement two unrelated interfaces.

11. T or F. Two classes cannot be defined in the same file since that would mean the file would have to have two different names.

12. T or F. Vectors may vary in size up to a fixed upper bound.

13. Effective use of vector elements requires casting.

14. Explain what super() does.

15. Explain what super(m) does.

16. Explain what super.print() does.

Thank you!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dsg123456789
Offline
Joined: 2006-04-14
Points: 0

1 f--order of method declaration doesn't matter

2 f--static methods cannot access instance variables, but instance methods can access static variables (import static would be a worthless keyword without it)

3 t--thats what subclassing is for

4 f--b could be a subclass of B, in which case it would be a B but it could use a different implementation of doIt()

5 f--static methods can only access static variables

6 f--classes can be nested (see Rectangle2D as an example). They are called Inner Classes. Multiple classes with the default access priveledges can be put into the same file (I think) but, for most classes, (those declared public, private, or protected), they must be in seperate files.

7 t--This is valid: private int i=7;

8 hmm--all variables are 'null' by default. This is probably false, but you could argue that null is a value, albeit a unique one.

9 f--NO MULTIPLE INHERITANCE. This was a big selling point of Java over C++; there would be no messy and confusing multiple-inherited methods with different definitions.

10 t--this is how multiple inheritance is accomplished without the risk

11 f--You can make a file named blah.java with these contents and it would compile:

class foo1{} class foo2{}

(I even tried it, and it still works in Java 5se)

12 f--Vectors dynamically resize.

13 f--Vector supports generics just like the rest of the collections.

14 super() calls the constructor of the superclass; it can only be invoked as the first call of a constructor.

15 super(m) is like super but it uses m as an argument

16 super.print() calls super's implementation of print()