205x Filetype PDF File size 0.19 MB Source: d1m75rqqgidzqn.cloudfront.net
FAQ 1. What are the OOPS concepts in Java? OOPs stands for Object-oriented programming. OOPs in Java organizes a program around the various objects and well-defined interfaces. The OOPs Concepts in Java are abstraction, encapsulation, inheritance, and polymorphism. These concepts aim to implement real-world entities in programs. 2. What are the 4 basics of OOP? The four basics of OOP are abstraction, encapsulation, inheritance, and polymorphism. These are the main ideas behind Java's Object-Oriented Programming. 3. What are the OOPS concepts in Java with examples? OOPs concepts in Java is known as object-oriented programming System. The following is a list of the OOPs concepts in Java with examples: 1. Class 2. Object 3. Inheritance 4. Polymorphism 5. Abstraction 6. Encapsulation 7. Association 8. Aggression 9. Composition 4. What explains the concept of Oops? OOPs help in creating a working method and variable that can be reused without compromising on security. The emphasis of OOPs concepts is on data rather than on functions and is mainly used in different object-oriented programming languages such as Java, C#, C++, Python, Perl, Ruby, etc. 5. What are the main features of OOPs? The main features of OOPs concepts in Java are Classes, Objects, Encapsulation, Data Abstraction, Polymorphism, Inheritance. 6. Why is OOPs concepts used? The reason for using OOPs concepts in Java is to implement various real-world entities such as polymorphism, abstraction, inheritance, etc., into programming. Another reason to use this is to ensure security of code by binding together the data and functions. 7. What are the advantages of OOPs? There are several benefits of implementing OOPs Concepts in Java. A few of the major advantages are as follows: Re-usability, Code maintenance, Data Redundancy, Security, Easy troubleshooting, Problem-Solving, Flexibility and Design Benefits. Java OOPs Concepts are one of the core development approaches that is widely accepted. 8. What is polymorphism in OOPs? In OOPs, Polymorphism is the process that allows us to perform a single action in multiple ways. This occurs when there are several classes related to each other through inheritance. In polymorphism, there are two types. Namely, compile-time polymorphism and runtime polymorphism. It helps us in reducing complexity. 9. Differences between Object-Oriented Programming, Procedural Oriented Programming, Structured Programming? Object-oriented programming Procedure oriented programming It is object oriented. It is structured oriented. It follows a bottom-up approach. It is divided into small parts called functions. These are divided into small parts called objects. It follows a top-down approach. These have specifiers like public, private, There are no access specifiers. protected. Adding new functions or data is easy. Adding new data and functions is not easy. It provides data hiding and it is more secure. This is less secure. Overloading is possible. Overloading is not possible. Examples are c++, java, python etc. Examples FORTRAN, Cobol etc. 10. What is Structured Programming? Structured programming • This divides a program into functions and modules, using this function and modules it makes the program more understandable and readable. It gives importance to functions rather than data and focuses on development on large software applications. • Example c, pascal. 11. Explain Composition in Java Composition in Java Composition is a strong association. Composition is an association that represents a part of a whole relationship where a part cannot exist without a whole. Let’s take an example of the relationship between School and Room. The school object consists of several rooms. Whenever the school object destroys automatically, all the room objects will be destroyed, i.e., without the existing school object, there is no chance of an existing dependent object. So these are strongly associated, and this relationship is called composition. If a whole is deleted, then all parts are deleted. So composition represents the part-of relationship. Whenever there is a composition between two entities, the created object cannot exist without the other object. Thus, in composition, both entities are dependent on each other. 12. What are the methods in Java ? Methods in Java A method in java is a block of code or collection of statements grouped together to complete a certain job or operation. A method is used to achieve the reusability of code. A method is written once and can be utilized many times. It also gives the easy modification and readability of code. A method is executed only when we call or invoke it. We have two categories of methods in java, i.e., pre-defined and user-defined. Predefined methods are the methods that are already defined in the Java class libraries. When the particular method is written by the user or programmer, it is known as a user-defined method. User-defined methods can be modified according to the requirement. Let's discuss: • Static method in Java • Abstract method in Java • Finalize method in Java • Equals method in Java Static Method in Java A method that has the static keyword in the declaration is known as the static method. In other words, a method that belongs to a class rather than an instance of a class is known as a static method. We can also create a static method by using the keyword static before the method name. The main benefit of a static method is that we can invoke the static method without even creating an object. It can access static data members and also change their values. It is used to create an instance method. It is invoked by using the class name. The main() method is a common example of the static method. Example: public class Demo { public static void main(String[] args) { displaymethod(); } static void displaymethod() { System.out.println("It is an example of static method."); } } Output: It is an example of a static method. Abstract Method in Java A method that is declared with keyword abstract is called an abstract method. The abstract method does not have an implementation or body, or block of code. The abstract method must always be declared in an abstract class, or we can say that if a class has an abstract method, it should be declared abstract. If a class has an abstract method, it should be declared abstract, but vice versa is not true, which means that an abstract class doesn’t need to have an abstract method compulsory. Also, If a normal class extends an abstract class, then the class must have to implement all the abstract parent class’s abstract methods, or it has to be declared abstract. Example: //abstract class area abstract class Area{ /* These two are abstract methods, the child class * must implement these methods */ public abstract int areaSquare(int s); public abstract int areaRectangle(int l, int b); //Normal method public void display(){ System.out.println("Normal method in abstract class Area"); } } //Normal class extends the abstract class class Demo extends Area{ /* If we don't provide the implementation of these two methods, the
no reviews yet
Please Login to review.