Further Vocab Unused in Lessons
Some Examples
abstract class Person {
public void organ() {
System.out.println("3 Organs");
}
}
class Joe extends Person {
public void organ() {
System.out.println("2 Organs");
}
}
Joe joe = new Joe();
joe.organ();
- Abstract Class - This class’s objects and methods can be referenced, however the class itself is not initialized.
- Inheritance/extends - takes aspects of an existing class and replicates it within another class using the extends method, simplifying code by a lot.
public class Polymorphism {
public void output(int x) {
System.out.println(x);
}
public void output(double x) {
System.out.println(x);
}
public void output(String x) {
System.out.println(x);
}
}
Polymorphism polymorphism = new Polymorphism();
polymorphism.output(100);
polymorphism.output(100.2);
polymorphism.output("Hello");
- Polymorphism - Multiple methods with the same name but different parameters, uses it at different times
- Overloading - When you use the same method name in a class each with different parameters.
- Overriding - When a subclass has the same name and parameters as the parent class
- Protected classes are used when you want to access the class within the package, subclasses. Can use extends to it to access.
class Person {
Person()
{
System.out.println("Person class Constructor");
}
}
// subclass Student extending the Person class
class Student extends Person {
Student()
{
super();
System.out.println("Student class Constructor");
}
}
// Driver Program
class Test {
public static void main(String[] args)
{
Student s = new Student();
}
}
- Subclass Constructor - A subclass constructor forms after extending a previous class, and using the super(); method will take a method and replicate it in the new class.
// Wrapper classes
int x = 5;
Integer xObj = x;
String thing = xObj.toString();
System.out.println(thing);
- Wrapper Classes - Wrapper classes allow converting primitives into objects and vice versa, which allows java to be object oriented, as primitives aren’t an object by default. Changes variables into object types.
- Truth tables - deines boolean function by choosing value for each possible value of arguments
- Big O Notation - Time complexity and figuring out the most efficient way of runining code