Objected-Oriented Programming

Cards (239)

  • Encapsulation is the practice of hiding data from other parts of your program, making it more secure and easier to manage.
  • Polymorphism refers to an object's ability to take on many forms.
  • Inheritance allows one class to inherit properties and methods from another class, creating a parent-child relationship between classes.
  • Encapsulation is a key OO concept known as "Information Hiding", which hides certain elements of the implementation of a certain class.
  • The whole idea behind encapsulation is to hide the implementation details and make sure that "sensitive" data is hidden from users.
  • An abstract class cannot be directly instantiated with the new operator.
  • Abstract classes can also have final methods (methods that cannot be overridden).
  • A method defined abstract must always be redefined in the subclass, thus making overriding compulsory.
  • There can be no object of an abstract class.
  • An abstract class can contain instance variables and methods that are fully implemented.
  • Encapsulation is defined as the wrapping up of data under a single unit, it is the mechanism that binds together code and the data it manipulates.
  • Through the statement super.print() in class Dog, it will access first the print() of the class Pet which displays the name and breed.
  • The color declared in class Dog will be displayed after the name and breed.
  • A parameterized constructor declared in class Dog can be used to set the value of "Brownie" in the Java application class (class PetDemo) and this value is passed to the attribute color using the this keyword.
  • In Java, the superclass's display() method can be accessed from within a subclass's display() method using the "super" keyword.
  • In encapsulation, the variables or data of a class is hidden from any other class and can be accessed only through any member function of own class in which they are declared.
  • Abstract is possible, Interface is not.
  • In what line does this code cause an error?
  • Instance Variables
  • What part of the code is the eat() and travel()?
  • Method Member
  • For items 14 - 15, refer to the following code fragment:
  • Both interface and abstract class are not possible for instantiation.
  • Encapsulation can be achieved by declaring all the variables in the class as private and writing public methods in the class to set and get the values of variables.
  • School bag is a real-time example of Encapsulation, it can keep our books, pens, etc.
  • You can have any numbers of levels of inheritance in your program as long as each class passes the "is a" test.
  • Multilevel inheritance means a superclass is inherited by a subclass, and the subclass is inherited by another subclass.
  • Program #4 uses the "super" keyword.
  • Program #5 uses the "super" keyword.
  • The name of the dog is Brownie and the breed is Aspin, with a brown color.
  • Programs #4 and #5 have similar outputs but different programming approaches dealing with inheritance.
  • Each class in a program has at least one default constructor, and all of them are executed whenever an instance of the lowest subclass is declared.
  • Programmers try to avoid using more than three levels of inheritance because each level adds a degree of complexity to the program and makes it a little more difficult to maintain and update.
  • Encapsulation Example #2: A Java Application Class named EncapTest has a method named setEmpName() to set the employee name, a method named setEmpAge() to set the employee age, and a method named setEmpSSN() to set the employee social security number.
  • In order to address the issue of setting and updating attributes, the mutator (setter) methods and accessor (getter) methods should be called as shown in the program.
  • Encapsulation Example #3: A Java Application Class named EncapTest has a method named setAccountBalance() to set the account balance, a method named getAccountBalance() to retrieve the account balance, and a method named getAccountBalance() to retrieve the account balance.
  • Encapsulation is a concept in object-oriented programming where the data and methods are bundled together.
  • Instead of using the setName() and getName() methods to access and update the attribute declared, it should be accessed and updated using the setter and getter methods.
  • Encapsulation Example #1: A Java Application Class named EncapDemo has a method named setName() to set the name and a method named getName() to retrieve the name.
  • Digit is a class that inherits from Number and implements Operation, performing several operations such as addition, subtraction, multiplication and division of the two numbers.