[go: up one dir, main page]

0% found this document useful (0 votes)
17 views9 pages

OOPS Concepts

Uploaded by

sundarmatsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

OOPS Concepts

Uploaded by

sundarmatsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

OOPS Concepts

-Basic Ques:
1.What is Coupling and Types?

Answer: when two classes (or) objects collaborate and work with each other to complete predefined
task. Types – loose coupling and Tight coupling.

2.What is Association?

Answer: Association refers to the relationship between the objects.

3. What are the differences between Object Oriented and Object-based programming language?

Answer: Object Oriented programming language –

1. Object-Oriented programming language supports all the features of Oops including inheritance
and Polymorphism.
2. Oops language don’t have built-in objects.
3. Examples: java, C++, etc.
Object-based programming language –
1. Object based programming language supports the usage of Object and encapsulation.
2. Object based programming language have built-in objects, for example JavaScript has window
object.
3. Examples: JavaScript, VB, etc.

4. What are the advantages and disadvantages of OOPs?

Answer: Advantages:

1. Oops language allows you to break the program into the small problems that can be easily
solved.
2. Code reusability.
3. Easy to maintain.
4. Flexibility and scalability.

Disadvantages:

1. Increased complexity.
2. Overuse of inheritance.
3. Steeper learning curve which means it is difficult to learn for beginners.

5. What is an Object in java?

Answer: An entity that has state and behavior is called as Object. It is a real-world entity. For examples,
car, chair, pen, table, etc...
6. What is class in java?

Answer: A class is template (or) blueprint form which objects are created. And class is group of objects.

7. What is method?

Answer: A method is a block of code or collection of statements are grouped together to perform a
certain task or operation.

8. What is abstract method?

Answer: A method does not have method body is called as abstract method. It is always declared inside
the abstract class only. If you declare a method as abstract, we can use abstract keyword.

9. What is constructor in java?

Answer: A constructor is a special type of method which is used to initialize the objects.

10. What is constructor overloading?

Answer: A class having more than one constructor with different parameter list, it is known as
constructor overloading.

11. What are the differences between constructor and method?

Answer: constructor:

- A constructor is used to initialize the objects.


- Doesn’t have any return type.
- A constructor name must be same as class name.
- Java compiler provides default constructor, when there is no constructor is available in a class.

Method:

- A method is used to expose the behavior of the object.


- A method must have return type.
- A method name may or may not be same as class name.
- A method doesn’t have any default method.

12. Why is java main () method being static?

Answer: java main () method is static. Because of the Object is not required to call a static method.

13. Can we execute a program without main method?

Answer: no, we cannot execute a program without main () method. Because when we run a program,
the JVM looks for the main method. If JVM could not find main method, it will show you run-time error
exception.

14.What is this keyword in java?

Answer: this keyword in java is a reference variable that refers to the current object.

15. What are the differences between Object and Class?


Answer: Object:

- Object is an instance of class.


- Object is a real-world entity.
- Object is created by using new keyword.
- Ex, pen, table, car, etc.

Class:

- Class is a group of similar objects.


- Class is a logical entity.
- Class is created by using class keyword.

-Inheritance:
1. what is inheritance?

Answer: Inheritance in java is a mechanism in which one object acquires all the properties and behavior
of a parent object. Also known as parent-child relationship.

2. Why use inheritance in java?

Answer: for method overloading, for code reusability.

3.what is subclass/child class?

Answer: The newly formed class which will created by taking the properties of an existing class/parent
class, it is known as sub class/child class. Also called as derived class.

4.what is superclass/base class?

Answer: A Super class is the class from where a subclass is inherits the features. Also called as base class.

5.what are the types of inheritance?

Answer: There are mainly three types of inheritance which are supported by java – 1) single inheritance,
2) multi-level inheritance, 3) hierarchical inheritance.

6.What is single inheritance in java?

Answer: when one class is derived from a single parent class is called as single inheritance.

7. What is multi-level inheritance?

Answer: When there is a chain of inheritance i.e., one class is derived from another class which is again
derived from another parent class, such type of inheritance is called multi-level inheritance.
8. What is hierarchical inheritance?

Answer: When one or more classes is derived from the single parent class. Such type of inheritance is
called as hierarchical inheritance.

9. what is Multiple inheritance?

Answer: When one class is derived from the two or more parent classes. Such type of inheritance is
called as multiple inheritance. Multiple inheritance is not supported by java.

10. Why multiple inheritance is not supported by java?

Answer: Because of ambiguity.

-Polymorphism:
11. What is method overloading?

Answer: if a class having multiple methods with same name and different parameters. It is known as
method overloading.

12. Why method overloading is not Possible by changing the return type of method only?

Answer: Because of ambiguity.

13. can we overload java main () method?

Answer: Yes, we can overload main method in java by method overloading. You can have any no. of main
methods in java program. But JVM calls main method which receives string array as arguments.

14. What is method overriding?

Answer: If a subclass has same method as declared in the parent class, it is known as method overriding.
Method overriding is used for run-time polymorphism.

15. Can we override Static method?

Answer: No, a static method cannot be overridden. It can be provided by the run-time polymorphism.

16. What are the differences between method overloading and method overriding?

Answer:

- method overloading is used to increase the readability of the program, while method overriding
is used to provide the specific implementation of the method.
- Method overloading performs within the class only, while method overriding occurs two classes.
- In case of method overloading, return type must be different. Whereas method overriding,
return type is same.
- Method overloading is the example of compile-time polymorphism, while method overriding is
the example of run-time polymorphism.

17. What is super keyword?

Answer: Super keyword is a reference variable which is used to refer the immediate parent class object.

18. What is final keyword and its usage?

Answer: Final keyword in java is a non-access modifier which is used to restrict the user. If you declare
any variable as final, you cannot change the value of final variable.

Usage: Stops value change, stop method overriding, Stop inheritance.

19. Is final method is inherited?

Answer: Yes, final method is inherited but you cannot override it.

20. Can we declare a constructor as final?

Answer: No, because constructed never be inherited.

21. What is polymorphism?

Answer: Polymorphism in java is a concept by which we can perform single action in different ways.

There are two types of polymorphism in java: runtime polymorphism, and compile-time polymorphism.

22. What is Run-time Polymorphism?

Answer: Run-time polymorphism is also known as dynamic method dispatch, is a process in which a
method call to an overridden method is resolved at run-time rather than compile-time.

23. What is Static binding and Dynamic binding?

Answer: Static binding: When type of the object is determined at compiled time (by the compiler), it is
known as static binding.

Dynamic binding: When type of the object is determined at run-time, it is known as dynamic binding.

24. What is Upcasting and down casting?

Answer: If a reference variable of the parent class is refers to the object of the child class, is called as
upcasting.

If a reference variable of the child class refers to the parent class object, is called as downcasting.

-Abstraction:
25. What is Abstraction?

Answer: Abstraction in java is a process of hiding all implementation details and showing only
functionality to the user.
For example, sending SMS, you type text and send it, you don’t know the internal process about the
message delivery.

26. What is abstract keyword, abstract class & abstract method?

Answer: abstract keyword is a non-access modifier which is used for classes and methods to achieve
abstraction.

A class which is declared with abstract keyword is known as abstract class. It can have abstract and non-
abstract methods.

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

27. What is interfaces in java?

Answer: Interface in java is a blue print of a class which is used to achieve abstraction and multiple
inheritance.

28. What are differences between the abstract class and Interface?

Answer:

- An abstract class can have abstract and non-abstract methods, while interface can have abstract
methods only.
- An abstract class can have static, non-static, final, non-final variables, while interfaces can have
final and abstract variables only.
- An abstract class does not supports multiple inheritance, while interfaces supports multiple
inheritance.

29. Multiple inheritance is not supported through class in java, but it is possible by an interface, why?

Answer: multiple inheritance is not supported in the case of class because of ambiguity. However, it is
supported in case of an interface because there is no ambiguity. It is because its implementation is
provided by the implementation class.

30. What is marker or tagged interface?

Answer: An interface which has no member is known as a marker or tagged interface, for
example, Serializable, Cloneable, Remote, etc.

31. What is nested interfaces?

Answer: An interface is declared within another interface is called nested interface.


-Encapsulation:
32. What is package?

Answer: A package is a folder which is collection of classes, methods, interfaces, abstract classes. There
are two types of packages – user-defined package and pre-defined or built-in package (the package
which is previously defined in java package API. For ex, java, awt, javax, swing etc.).

33. What is access modifier? And its types?

Answer: Access modifier in java specifies the accessibility or scope of a field, method, constructor or
class. There are 4 types of access modifiers in java.

- Private: can accessible only within the class. It cannot be accessed outside the class.
- Default: can accessible only within the package. Cannot be accessible outside the package.
- Protected: can accessible within the package and outside the package through the child class.
- Public: can be accessible everywhere i.e., inside and outside the package and inside and outside
the class.

34. What is encapsulation?

Answer: Encapsulation in java is a process of wrapper code and data together into a single unit. For
example, a capsule is mixed with several medicines.

35: What are the Advantages of encapsulation?

Answer:

- provides control over the data.


- Hide all implementation details.
- You can make a class read-only or write-only by providing setter and getter methods.

36. What is object cloning?

Answer: Object cloning in java is a way to create an exact copy of an object.

37. What is Java wrapper class?

Answer: The wrapper class in java is used to convert primitive data types into objects and vice versa.

38. What is compile-time polymorphism?

Answer: The compile-time polymorphism is a polymorphism that is resolved during the compilation
process.

39. what is subpackage in java?

Answer: A package inside another package is called subpackage.

40. What is java commend-line arguments?

Answer: The java command-line argument is an argument i.e. passed at the time of running the java
program.
41. What is blank or uninitialized final variable?

Answer: A final variable that is not initialized at the time of declaration is known as blank final variable.

42. What is recursion in java?

Answer: Recursion in java is a process in which a method calls itself continuously. It makes the code
compact but complex to understand.

43. Define Destructor?

Answer: A destructor is a special method which is automatically called when the object is made of scope
or destroyed.

45. What is ternary operator?

Answer: ternary operator is the only conditional statement that takes three arguments. Arguments and
results are of different data types, and it depends on the function.

You might also like