Object Oriented Programming Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is class inheritance?

Inheritance allows a new class (subclass or derived class) to inherit the characteristics and behaviors of an existing class (superclass or base class).

How is inheritance performed in Java?

Java uses the 'extends' keyword to indicate a derived class. Example: class Animal { void eat() { System.out.println("This animal eats food."); } } class Dog extends Animal { void bark() { System.out.println("The dog barks."); } } public class Main { public static void main(String[] args) { Dog myDog = new Dog(); myDog.eat(); // Inherited method from Animal class myDog.bark(); // Method specific to the Dog class } }

What are the two types of polymorphism in Java?

Method Overloading (Compile-time) and Method Overriding (Runtime)

What is the difference between Method Overloading and Method Overriding?

Method overloading allows a class to have multiple methods with the same name but different parameter lists, enabling flexibility within the same class. Method overriding occurs when a subclass provides a specific implementation for a method already defined in its superclass, allowing for dynamic method invocation based on the actual object type at runtime.

What is the 2nd parameter of JOptionPane.showMessageDialog()?

The Message This is what displays in the message box.

What is the 4th parameter of JOptionPane.showMessageDialog()?

The Message Type Determines the icon and style of the dialog JOptionPane.PLAIN_MESSAGE JOptionPane.INFORMATION_MESSAGE JOptionPane.QUESTION_MESSAGE JOptionPane.WARNING_MESSAGE JOptionPane.ERROR_MESSAGE

What is the 1st parameter of JOptionPane.showMessageDialog()?

The Parent Component Typically a Swing component like a JFrame, but we've only ever just used null.

What is the 3rd parameter of JOptionPane.showMessageDialog()?

The Title This is what shows on the title bar of the dialog box.

What is polymorphism?

The ability of a message to be displayed in more than one form. It allows objects of different types to be treated as objects of a common type. It enables a single interface to represent different underlying types, providing a way to write code that can work with objects of various classes in a unified manner.

Give an example of method overriding in Java

class Animal { void makeSound() { System.out.println("Some generic sound"); } } class Dog extends Animal { void makeSound() { System.out.println("Bark"); } } Example: Animal myAnimal = new Dog(); myAnimal.makeSound();

Give an example of method overloading in Java

class MathOperations { int add(int a, int b) { return a + b; } double add(double a, double b) { return a + b; } } Example: MathOperations mathOps = new MathOperations(); int result1 = mathOps.add(5, 10); double result2 = mathOps.add(3.5, 7.2);

How do you import JOptionPane?

import javax.swing.JOptionPane;

How do you get input using JOptionPane?

import javax.swing.JOptionPane; String userInput = JOptionPane.showInputDialog(null, "Enter your name:", "Input", JOptionPane.QUESTION_MESSAGE);

How do you initialize an array of a set length?

int myArray[] = new int[5];


Set pelajaran terkait

Intro to Financial Management- Accounting Exam 2

View Set

BUS 106 Chapter 7 Questions and Problems

View Set

Six Sigma Root Cause Analysis and Waste Elimination

View Set

Adult 1: Exam 2 practice questions

View Set

CH. 04: Network Protocols and Routing

View Set

Chapter 14: Agricultural Entomology

View Set

AUDITORY SYSTEM AND TEMPORAL LOBE FUNCTION

View Set

Life & Annuity state exam prep (examfx)

View Set