In Java, this is a blueprint for creating objects
What is a Class?
This operator is used to join strings in Java.
what is + operator?
This principle bundles fields and methods into a single unit.
public class Test {
public static void main(String[] args) {
int x = "10";
System.out.println(x);
}
}
What is int?
(Data type mismatch)
int a = 5, b = 3;
System.out.println(a + b);
What is 8
This keyword is used for inheritance in Java.
What is extends?
This is the result of 10 % 3
What is 1?
This principle allows one interface to represent many different forms.
What is polymorphism?
public class Compare {
public static void main(String[] args) {
int x = 5;
if (x = 5) {
System.out.println("Yes");
}
}
}
What is =?
(Uses = instead of == in if statement)
int x = 7;
System.out.println("Result: " + (x * 2));
What is Result: 14?
This OOP principle hides internal details while showing only essential features.
What is abstraction?
This operator compares the values of two variables for equality.
What is == (is equal to)?
This principle lets a child class reuse or override methods of its parent class.
What is inheritance?
public class Demo {
public void main(String[] args) {
System.out.println("Hello, world!");
}
}
What is static?
(Missing static keyword in main method)
int a = 10, b = 20;
System.out.println(a > b ? "A is bigger" : "B is bigger");
What is B is Bigger?
This OOP concept allows one method or operator to behave differently based on the object that is calling it.
What is polymorphism?
This operator is used to increase a variable’s value by 1.
what is ++ (increment)?
When a subclass defines a method with the same name and parameters as its parent, this occurs.
What is method overriding?
public class LoopTest {
public static void main(String[] args) {
for (int i = 0; i < 5; i--) {
System.out.println(i);
}
}
}
What is i--?
(Will cause an infinite loop)
for(int i=1; i<=3; i++) {
System.out.print(i + " ");
}
What is 1 2 3?
This keyword is used to refer to the instantiated object’s variable instead of the constructor parameter.
What is this?
int a = 5, b = 10; System.out.println(a > 2 && b < 20);
What is true?
This is the main benefit of using OOP
What is DRY?
public class BankAccount {
private double balance = 1000;
public static void main(String[] args) {
BankAccount acct = new BankAccount();
System.out.println(acct.balance);
}
}
What is acct.balance?
(Accessing a private variable directly, use a getter method to access private variable)
class Animal {
void sound() {
System.out.println("Animal sound"); }
}
class Dog extends Animal {
void sound() {
System.out.println("Bark"); }
}
public class Test {
public static void main(String[] args) {
Animal a = new Dog();
a.sound();
}
}
What is bark?