Minggu, 26 November 2017

Java Fundamental Section 7

1. Static classes can't return instances of the parent class when the parent class uses a private constructor. True or false?
False (*)

2. Static methods can't act like "setter" methods. True or false?
False (*)

3. Static methods can read static variables. True or false?
True (*)

4. What is Polymorphism?
The concept that a variable or reference can hold multiple types of objects. (*)

5. Would this code be correct if a Dog is a HousePet? Why or Why not? 
HousePet Scooby = new Dog();
Yes, because polymorphism allows this since Dog is a subclass of HousePet. (*)

6. Why would a programmer use polymorphism rather than sticking to a standard array?
Because arrays only work using the same object type and polymorphism provides a way around this. (*)

7. The constructor of a class has the same name as the class. True or false?
True (*)

8. Which of the following may be part of a class definition?
all of the above (*)

9. What operator do you use to call an object's constructor method and create a new object?
New (*)

10. An access modifier is a keyword that allows subclasses to access methods, data, and constructors from their parent class. True or false?
True (*)

11. Which of the following is the correct way to call an overriden method needOil() of a super class Robot in a subclass SqueakyRobot?
super.needOil(); (*)

12. What is the Java Applet?
(Choose all correct answers)
A web-based Java program that is embedded into a web browser. (*)
A graphic visual included in Java. (*)

13. Which of the following is a possible way to overload constructors?

 

14. Which of the following could be a reason to return an object?
The method makes changes to the object and you wish to continue to use the updated object outside of the method. (*)

15. Consider the following:

There is a method A that calls method B. Method B is a variable argument method. 

With this, which of the following are true?
(Choose all correct answers)
Method A can invoke method B twice, each time with a different number of arguments. (*)
When invoked, method B creates an array to store some or all of the arguments passed to it from method A. (*)

1. It is possible to inherit from an abstract class. True or false?
True (*)

2. If a class is immutable then it must be abstract. True or false?
False (*)

3. Which of the following would be most beneficial for this scenario?

Joe is a college student who has a tendency to lose his books. Replacing them is getting costly. In an attempt to get organized, Joe wants to create a program that will store his textbooks in one group of books, but he wants to make each book type the subject of the book (i.e. MathBook is a book). How could he store these different subject books into a single array?
Using polymorphism. (*)

4. Static classes can exist as stand alone classes. True or false?
False (*)

5. Public static variables can't have their value reset by other classes. True or false?
False (*)

6. A static variable is always publicly available. True or false?
False (*)

7. Which of the following correctly defines overloading?
Having more than one constructor with the same name but different arguments. (*)

8. A team is working on a coding project. They desire that all portions of their code should have access to the classes that they write. What access modifier should be used for each class?
Public (*)

9. It is possible to overload a method that is not a constructor. True or False?
True (*)
 
10. What value will be returned when the setValue method is called?


37(*)

11. A class can only have one constructor. True or false?
False (*)

12. The following statement compiles and executes. What do you know for certain? 

tree.grows(numFeet);
grows must be the name of a method. (*)

13. Why is it not possible to extend more than one class at a time in an inheritance hierarchy chain?
It is not necessary considering all public content is passed from super class to subclass and further to their subclass and that subclass' subclass and so on. (*)

14. Which of the following correctly describes an "is-a" relationship?
A helpful term used to conceptualize the relationships among nodes or leaves in an inheritance hierarchy. (*)

15. It is possible for a subclass to be a superclass. True or false?
True (*)

Tidak ada komentar:

Posting Komentar