Object Oriented Programming

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is an abstract class?

- A class which is declared as abstract - It can have abstract and non-abstract methods - It needs to be extended and its method implemented - It cannot be instantiated

What is a parameterized constructor?

- A constructor which has a specific number of parameters is called a parameterized constructor - The parameterized constructor is used to provide different values to the distinct objects. However, you can provide the same values also.

Define inheritance in Java.

- A mechanism in which one object acquires all the properties and behaviors of a parent object - The idea behind it is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you can reuse methods and fields of the parent class. Moreover, you can add new methods and fields in your current class also. - Inheritance represents the IS-A relationship which is also known as a parent-child relationship

What is an abstract method?

- A method which is declared as abstract and does not have implementation is known as an abstract method

What is object oriented programming?

- A methodology or paradigm to design a program using classes and objects - Simplifies the software development and maintenance by providing some concepts: object, classes, inheritance, polymorphism, abstraction, encapsulation

What is a default constructor?

- A no-argument constructor that the Java compiler inserts on your behalf; it contains a default call to super(); which is the default behavior - If you implement any constructor then you no longer receive a default constructor

What is abstractation?

- A process of hiding the implementation details and showing only functionality to the user - Lets you focus on what the object does instead of how it does i

What is encapsulation in OOP?

- A process of wrapping code and data together into a single unit, for example, a capsule which is mixed of several medicines - Fully encapsulated classes are created in Java by making all the data members of the class private, use setter and getter methods to set and get the data in it - The Java Bean class is the example of a fully encapsulated class

What is a constructor?

- A special type of method used to initialize the object - A block of codes similar to the method. It is called when an instance of the object is created, and memory is allocated for the object

What is constructor overloading?

- A technique of having more than one constructor with different parameter lists arranged in a way that each constructor performs a different task. They are differentiated by the compiler by the number of parameters in the list and their types

What are the two ways to achieve abstraction in Java?

- Abstract class (0 to 100%) - Interface (100%)

What is an object?

- Any entity that has state and behavior is known as an object - An Object can be defined as an instance of a class - An object contains an address and takes up some space in memory - Objects can communicate without knowing the details of each other's data or code, the only necessary thing is the type of message accepted and the type of response returned by the objects

What are the different ways to overload a method?

- Change the number of arguments - Change the data type

What terms are associated with inheritance?

- Class (a group of objects which have common properties) - Sub class/Child class (class which inherits another class) - Super class/Parent class (class from where a subclass inherits its features) - Reusability (mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new one)

What is hierarchical inheritance?

- Class B and Class C derived from Class A

What is single inheritance?

- Class B derived from Class A

What is multilevel inheritance?

- Class C derived from Class B derived from Class A

What are the rules to keep in mind when calling a constructer?

- Constructor name must be the same as its class name - A constructor must have no explicit return type - A Java constructor cannot be abstract, static, final, and synchronized

A _____ is used to initialize the state of an object, while a _____ is used to expose the behavior of an object. (Constructors vs. Methods).

- Constructor, method

The Java compiler provides a default _____ if you don't have any in a class, while the _____ is not provided by the compiler in any case. (Constructors vs. Methods).

- Constructor, method

What does changing the number of arguments accomplish?

- Creates static methods so there is no need to create instance for calling methods

What does specialization mean?

- Creating new subclasses from an existing class - If it turns out that certain attributes, associations, or methods only apply to some of the objects of the class, a subclass can be created

Which access modifier is this? Within class: Y Within package: Y Outside package by subclass only: N Outside package: N

- Default access modifier

What are the two types of constructors?

- Default constructor - Parameterized constructor

In case of method overloading, parameter must be _____, while in case of method overriding, parameter must be _____. (Method Overloading vs. Method Overriding).

- Different, the same

What is the syntax represents an instance of inheritance?

- Extends - e.g. class Employee --> class Programmer extends Employee

True or False: Changing the return type of the method will overload the method by means of changing the data type.

- False, changing the return type is not enough to overload the method

True or False: Return type must not be the same or covariant in method overriding. (Method Overloading vs. Method Overriding).

- False, must be the same

The classes Piece of Luggage and Piece of Cargo partially share the same attributes. From a domain perspective, the two classes are also very similar. During _____, the shared characteristics are combined and used to create a new superclass Freight. Piece of Luggage and Piece of Cargo become subclasses of the class Freight. Therefore the properties that are common to the classes Piece of Luggage and Piece of Cargo are placed in the superclass Freight - Identification, Weight and ID-Number are those properties.

- Generalization

What is method overloading?

- If a class has multiple methods having same name but different in parameters - Having the same name of the methods increases the readability of the program when programming for only one operation Suppose you have to perform addition of the given numbers but there can be any number of arguments, if you write the method such as a(int,int) for two parameters, and b(int,int,int) for three parameters then it may be difficult for you as well as other programmers to understand the behavior of the method because its name differs

A constructor is invoked _____, while a method is invoked _____. (Constructors vs. Methods).

- Implicitly, explicitly

What are the 4 pillars of OOP?

- Inheritance - Polymorphism - Encapsulation - Abstractation

What are the advantages of encapsulation?

- Make the class read-only or write-only (by providing only a setter or getter method) - It provides you the control over the data by writing the logic inside the setter method - It is a way to achieve data hiding in Java because other class will not be able to access the data through the private data members - The encapsulate class is easy to test and as such is better for unit testing

What are the advantages of inheritance?

- Method Overriding (so runtime polymorphism can be achieved) - Code Reusability

_____ is used to increase the readability of the program, while _____ is used to provide the the specific implementation of the method that is already provided by its super class. (Method Overloading vs. Method Overriding).

- Method overloading, method overriding

_____ is the example of run time polymorphism, while _____ is the example of compile time polymorphism. (Method Overloading vs. Method Overriding).

- Method overriding, method overloading

A _____ must have a return type, while a _____ must not have a return type. (Constructors vs. Methods).

- Method, constructor

The _____ name may or may not be same as class name, while the _____ name must be same as the class name. (Constructors vs. Methods).

- Method, constructor

What are the characteristics of an abstract class?

- Must be declared with an abstract keyword - Can have abstract and non-abstract methods - Cannot be instantiated - Can have constructors and static methods also - Can have final methods which will force the subclass not to change the body of the method

Can a static method be overridden?

- No, a static method cannot be overridden (proven by runtime polymorphism) - The static method is bound with class whereas instance method is bound with an object. Static belongs to the class area, and an instance belongs to the heap area.

What are the advantages of OOPs over Procedure Oriented Programming?

- OOPs makes development and maintenance easier whereas in a procedure-oriented programming language it is not easy to manage if code grows as project size increases. - OOPs provides data hiding whereas in a procedure-oriented programming language a global data can be accessed from anywhere.

What are the different types of inheritance in Java?

- On the basis of class, there can be three types of inheritance in java: single, multilevel and hierarchical - In java programming, multiple and hybrid inheritance is supported through interface only

Which access modifier is this? Within class: Y Within package: N Outside package by subclass only: N Outside package: N

- Private access modifier

Which access modifier is this? Within class: Y Within package: Y Outside package by subclass only: Y Outside package: N

- Protected access modifier

Which access modifier is this? Within class: Y Within package: Y Outside package by subclass only: Y Outside package: Y

- Public access modifier

What is the difference between a read-only and a write-only class?

- Read-only classes only have getter methods - Write-only classes only have setter methods

When it comes to _____, if there is a property that is only applicable to a specific subclass, such as Degree of Hazardousness, that property is placed in the class Piece of Cargo where-in this class also has all the properties of the Freight class with the concept of generalization.

- Specialization

What is a class?

- Templates that are used to create objects, and to define object data types and methods - Core properties include the data types and methods that may be used by the object - A class can also be defined as a blueprint from which you can create an individual object - A class doesn't consume any space

What is polymorphism and how is it used in OOP?

- The ability of an object to take on many forms - The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object

What rules are associated with method overriding?

- The method must have the same name as in the parent class - The method must have the same parameter as in the parent class - There must be an IS-A relationship (inheritance)

What is generalization?

- The process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass - Shared characteristics can be attributes, associations, or methods.

What is an access modifier and how many types are there in Java? What are the types?

- There are 4 access modifiers in java that specify accessibility (scope) of a data member, method, constructor or class - Private, default, protected and public

What is method overriding used for?

- To provide the specific implementation of a method which is already provided by its superclass - For runtime polymorphism

Why is multiple inheritance not supported in Java?

- To reduce the complexity and simplify the language, multiple inheritance is not supported in java - Consider a scenario where A, B, and C are three classes. The C class inherits A and B classes. If A and B classes have the same method and you call it from child class object, there will be ambiguity to call the method of A or B class

True or False: Any Java object that can pass more than one IS-A test is considered to be polymorphic.

- True

True or False: In Java, all Java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object.

- True

True or False: In java, method overloading can't be performed by changing return type of the method only. Return type can be same or different in method overloading, but you must change the parameter. (Method Overloading vs. Method Overriding).

- True

True or false: In Java, there are both access modifiers and non-access modifiers.

- True

True or False: You can overload the main() method in Java.

- True - You can have any number of main methods in a class by method overloading, but JVM calls main() method which receives string array as arguments only

What is method overriding?

- When a subclass has the same method as declared in the parent class - In other words, if a subclass provides the specific implementation of the method that has been declared by one of its parent class, it is known as method overriding

When is a constructor called?

- When an object is created, compiler makes sure that constructors for all of its sub-objects (its member and inherited objects) are called - If members have default constructors or constructor without parameter then these constructors are called automatically, otherwise parameterized constructors can be called using initializer list

Method overloading is performed _____. Method overriding occurs in _____ that have _____. (Method Overloading vs. Method Overriding).

- Within a class, two classes that have IS-A (inheritance) relationship

Can access modifiers be used with method overriding?

- Yes, but the overridden method must not be more restrictive than the access modifier

Why is it called a constructor?

- it constructs the values at the time of object creation. It is not necessary to write a constructor for a class - Jave compiler creates a default constructor if your class doesn't have any


संबंधित स्टडी सेट्स

Chapter 8 - Respiratory Function

View Set

The Heart Structures and Functions

View Set

Chapter IV Life Insurance Policy, Provisions, Options and Riders (15 Exam Questions)

View Set

S.O.A.P Subjective and Objective

View Set

Abeka Vocabulary Spelling Poetry V Review Quiz Four

View Set

Pearson My Programing Lab Python lab 6

View Set

United States Government and Politics

View Set

ATI RN Infection: Urosepsis 3.0 Case Study Test

View Set

The history of the Statue of Liberty

View Set