Object Oriented Programming with Java
Quiz Answers
Q1) Which of the following statements about object-oriented programming is INCORRECT?
- In object-oriented programming. Data and functions that manipulate them are usually separate entities that
- interact with each other.
- Objects often interact with each other much like they do in real life.
- Objects can hide certain details from other objects
- Objects can contain data, called "properties", and functions that manipulate the data, called "methods".
Q2) Which of the following keyword is used in Java to define the blueprint of an object?
- class
- private
- constructor
- method
Q3) In Java, which of these is a correct statement to call the constructor of the ancestor class named "Animal" with no parameters?
- super();
- ancestor(),
- super.constructor();
- Animal.constructor();
Q4) If we want to extend a base class called "Flower" and call it "Rose", which of these is the correct syntax to do that in Java?
public class Rose as Flower {
}
public class Flower extends Rose {
}
public class Flower descendent Rose
public class Rose extends Flower {
}
Q5) Which of the follow statement is CORRECT about abstraction?
- Abstraction is the practice of making code more obscure to read and understand so other people who look at the code have no idea what it does.
- Abstraction is a way for base objects to behave more generically when compared to their descendants.
- Abstraction is a principle of object-oriented programming where abstract variable names are used to make the code more compact.
- Abstraction is the practice of hiding complex or proprietary processes from users of a class.
Q6) In Java, if we have a property String secretCode, which of these declarations hides it from other users of the objects?
- abstract String secretCode;
- nonpublic String secretCode;
- private String secretCode;
- hidden string secretCode;
Q7) Which of these statements about polymorphism is correct?
- Polymorphism allows objects to become other types of unrelated objects during program execution.
- Polymorphism makes it possible for methods of objects in the same object hierarchy to have different behaviors.
- Polymorphism refers to the principle of object-oriented programmer where one definition of an object can have multiple names.
- Polymorphism allows methods of an object to have different names in their descendents.
Q8) If we want a method public double offer BestPrice() in our object to have a completely different algorithm than the one in the ancestor class, how would we redefine it in our object?
- #OVERRIDE public double offer BestPrice()
- public double offer BestPrice()
- @Redefine public double offer BestPrice()
- @Override public double offerBestPrice()
Q9) What does the Java keyword "protected" do?
- When it is in front of a property or method definition, it makes that property or method accessible from within the class itself and ALSO from any descendent classes.
- It is used in front of a class declaration to make sure that the class CANNOT be inherited by any descendent classes.
- It makes everything in the class protected and inaccessible to any code outside of the class.
- When it is in front of a property or method definition, it makes that property or method accessible from within the class itself ONLY
Q10) Which of the following statements about constructors in Java is CORRECT?
- All the parameters in a constructor definition are optional at runtime.
- An object CANNOT have multiple constructors.
- An object CAN have multiple constructors but they must have different parameter lists. The one matching the parameters provided by the caller at runtime will be called.
- An object CAN have multiple constructors as long as they have different names.
2 Comments
Which of the following statements about object-oriented programming is INCORRECT
ReplyDeleteVery interesting article
ReplyDelete