OOP Polymorphism

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/8

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

9 Terms

1
New cards

Polymorphism

  • the concept of entity providing multiple implementations or behaviors

  • ability of a variable to change behavior according to what object instance is holding.

  • This allows multiple objects of different subclasses to be treated as objects as a single parent class

2
New cards

Compile-Time Or Static Polymorphism

  • refers to behaviour that is resolved when your Java

class is compiled.

  • Method overloading is using method of same name to do different things based on the parameters passed.

3
New cards
<ul><li><p><span style="color: yellow;">Illustration — Method Overloading</span></p></li><li><p>return</p></li><li><p>new</p></li></ul><p></p>
  • Illustration — Method Overloading

  • return

  • new

class MultiplyFun {

int multiply(int a, int b) {

r____ a * b;

}

int multiply(int a, int b, int c) {

return (a * b) + c;

}

}

public class Main {

public static void main(String[] args) {

MultiplyFun mf = __ MultiplyFun();

System.out.println(mf.multiply(2, 4));

System.out.println(mf.multiply(2, 7, 3));

}

}

4
New cards
  • Illustration — Method Overloading

  • void overloading

  • obj

class OperatorOVERDDN {

v__ o____(String str1, String str2) {

String s = str1 + str2;

System.out.println("Concatenated String = " + s);

}

void operator(int a, int b) {

int c = a + b;

System.out.println("Sum = " + c);

}

}

class Main {

public static void main(String[] args) {

OperatorOVERDDN __= new OperatorOVERDDN();

obj.operator(2, 3);

obj.operator("joe", "now");

}

}

5
New cards

Run-Time Or Dynamic Polymorphism

  • Definition: Resolved when your Java class is run by the JVM.

  • Key Mechanism: Method overriding by a subclass is an example of run-time polymorphism.

6
New cards

Method Overriding Explained

  • Child classes provide their own implementation of a method already defined in the parent class.

  • The JVM determines which version of the method to execute—parent or child—based on the object used to invoke the method.

7
New cards

class Parent {

void print() {

System.out.println("Parent");

}

}

class SubClass1 extends Parent {

void print() {

System.out.println("SubClass 1");

}

}

class SubClass2 extends Parent {

void print() {

System.out.println("SubClass 2");

}

}

public class TestPolymorphism3 {

public static void main(String[] args) {

Parent a;

a = new SubClass1();

a.print(); 

a = new SubClass2();

a.print();

}

}

8
New cards

Overriding vs Overloading

knowt flashcard image
9
New cards

advantage of polymorphism

knowt flashcard image

Explore top flashcards

CGT 163 Exam 1
Updated 967d ago
flashcards Flashcards (81)
Chapter 1 & 2
Updated 231d ago
flashcards Flashcards (65)
Body Mechanics
Updated 197d ago
flashcards Flashcards (34)
Biology term 1 y9
Updated 883d ago
flashcards Flashcards (49)
CGT 163 Exam 1
Updated 967d ago
flashcards Flashcards (81)
Chapter 1 & 2
Updated 231d ago
flashcards Flashcards (65)
Body Mechanics
Updated 197d ago
flashcards Flashcards (34)
Biology term 1 y9
Updated 883d ago
flashcards Flashcards (49)