


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Designed for students in the 400-level Artificial Intelligence course (CPE 421) , Faculty of Engineering, this material is aligned with the NUC curriculum and prepares students for both academic assessments and real-world applications.
Typology: Cheat Sheet
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Allows a child class (subclass) to inherit properties (fields/methods) from a parent class (superclass).
class Parent { void show() { System.out.println("Parent class method"); } } class Child extends Parent { void display() { System.out.println("Child class method"); } } public class Main { public static void main(String args[]) { Child obj = new Child(); obj.show(); // Inherited method obj.display(); // Own method } }
Subclass provides its own version of a method already defined in the superclass.
class Parent { void show() { System.out.println("Parent method"); }
class Child extends Parent { @Override void show() { System.out.println("Child method"); } } public class Main { public static void main(String args[]) { Parent obj = new Child(); obj.show(); // Child method runs (Overriding) } }
Same method name behaves differently based on context.
class MathOps { int add(int a, int b) { return a + b; } int add(int a, int b, int c) { return a + b + c; } }
Shows only necessary details while hiding implementation.
abstract class Animal { abstract void makeSound(); } class Dog extends Animal { void makeSound() { System.out.println("Bark"); }
Common Methods:
public class StringDemo { public static void main(String args[]) { String str = " Hello Java! "; System.out.println("Original: " + str); System.out.println("Length: " + str.length()); System.out.println("Trimmed: " + str.trim()); System.out.println("Uppercase: " + str.toUpperCase()); System.out.println("Character at 1: " + str.charAt(1)); System.out.println("Substring: " + str.substring(2, 7)); System.out.println("Replaced: " + str.replace("Java", "World")); } }