0% found this document useful (0 votes)
3 views2 pages

DAY3 Notes

The document discusses key concepts in Java, focusing on polymorphism and abstraction. It explains polymorphism as the ability to treat objects as instances of their parent class, differentiating between compile-time and runtime polymorphism. Additionally, it covers abstraction, abstract classes, interfaces, and methods, highlighting their roles and differences in object-oriented programming.

Uploaded by

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

DAY3 Notes

The document discusses key concepts in Java, focusing on polymorphism and abstraction. It explains polymorphism as the ability to treat objects as instances of their parent class, differentiating between compile-time and runtime polymorphism. Additionally, it covers abstraction, abstract classes, interfaces, and methods, highlighting their roles and differences in object-oriented programming.

Uploaded by

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

DAY3:

1. Polymorphism, 2. Abstraction

QUESTIONS(Theory)

1. What is meant by polymorphism?

Polymorphism in Java is a core concept of object-oriented programming (OOP) that allows objects to
be treated as instances of their parent class. It facilitates flexibility and the ability to define methods
in multiple forms. Polymorphism is primarily achieved through method overriding and method
overloading.

2. Difference between Static binding and Runtime polymorphism?

Compile Time Polymorphism Run time Polymorphism

In Compile time Polymorphism, the call is In Run time Polymorphism, the call is not
resolved by the compiler. resolved by the compiler.

It is also known as Static binding, Early It is also known as Dynamic binding, Late
binding and overloading as well. binding and overriding as well.

It is achieved by method overloading It is achieved by virtual functions and pointers.

It provides fast execution because the It provides slow execution as compare to early
method that needs to be executed is binding because the method that needs to be
known early at the compile time. executed is known at the runtime.

Compile time polymorphism is less flexible Run time polymorphism is more flexible as all
as all things execute at compile time. things execute at run time.

3. What is mean by Abstraction?

Abstraction refers to hiding the implementation details of a code and exposing only the necessary
information to the user.

4. Difference between Abstract class and interface?

Abstract classes allow you to define some default behavior while forcing subclasses to implement
specific methods. Interfaces focus purely on behavior, providing no concrete methods.
5. What is mean by abstract method?

Abstract classes and methods provide a way to define a blueprint or template for a class without
providing a complete implementation.

6. Can we create object for abstract class?

You can't create an object of an abstract class type. However, you can use pointers and references to
abstract class types. You create an abstract class by declaring at least one pure virtual member
function.

7. In interface, can we make method as static?

An interface can declare static methods, which are invoked without reference to a particular object.
Static interface methods are distinct from default methods, abstract interface methods, and non-
static private interface methods, all of which are instance methods.

8. In interface, can we make method as final?

No, we can not declare interface as final . Interface in Java is similar to a class but it contains only
abstract methods and fields, which are final and static . Since all the methods are abstract ;
therefore, we cannot instantiate interface.

9. How will achieve multiple inheritance in java, write a code for that?

interface Parent1

void method1();

interface Parent2

void method2();

class Child implements Parent1, Parent2 { ... }

In this example, we have two interfaces, Parent1 and Parent2 , each with a method. The Child class
implements both interfaces, effectively achieving multiple inheritance.

You might also like