Anda di halaman 1dari 1

JAVA OOP CHEAT SHEET Learn JAVA from experts at https://www.edureka.


Object Oriented Programming in Java Inheritance

Java is an Object Oriented Programming language Single Inheritance Hierarchical Inheritance
that produces software for multiple platforms. An Class A {
object-based application in Java is concerned with //your parent class code Class A {
declaring classes, creating objects from them and } //your parent class code
interacting between these objects. }
Class B extends A {
//your child class code
Java Class } Class B extends A {
//your child class code
class Test { }
// class body Multi Level Inheritance
member variables Class A { Class C extends A {
methods //your parent class code //your child class code
} } }
Class B extends A {
//your code
Java Object } Multiple Inheritance
//Declaring and Initializing an object Class C extends B {
Test t = new Test(); //your code Class A {
} //your parent class code
Class B {
Constructors Hybrid Inheritance
//your parent class code
/ \ |
Default Constructor Class C extends A,B {
B C (OR) B
class Test{ //your child class code
/ \ / \
/* Added by the Java Compiler at the Run Time }
public Test(){
*/ Polymorphism Abstraction
public static void main(String args[]) {
Test testObj = new Test();
} Compile Time Polymorphism Abstract Class
} class Calculator { public abstract class MyAbstractClass
static int add(int a, int b){ {
return a+b; public abstract void abstractMethod();
Parameterized Constructor } public void display(){
static double add( double a, double b){ System.out.println("Concrete method");
public class Test {
return a+b; }
int appId;
} }
String appName;
public static void main(String args[]){
//parameterized constructor with two parameters
Test(int id, String name){ Interface
this.appId = id;
} //Creating an Interface
this.appName = name;
} public interface Bike { public void start(); }
//Creating classes to implement Bike interface
void info(){
Run Time Polymorphism class Honda implements Bike{
System.out.println("Id: "+appId+" Name: "+appName);
public void start() {
} public class Mobile{ System.out.println("Honda Bike");
void sms(){System.out.println("Mobile class");} } }
public static void main(String args[]){ } class Apache implements Bike{
Test obj1 = new Test(11001,"Facebook");
public void start() {
Test obj2 = new Test(23003,"Instagram"); //Extending the Mobile class System.out.println("Apache Bike");; public class OnePlus extends Mobile{ } }; //Overriding sms() of Mobile class class Rider{
} void sms(){ public static void main(String args[]){
} System.out.println(" OnePlus class"); Bike b1=new Honda();
} b1.start();
Bike b2=new Apache();
public static void main(String[] args) { b2.start();
J ava C e r t i f i c a t i o n OnePlus smsObj= new OnePlus();
} }

Training }
public class Artist {
Modifiers in Java private String name;
//getter method
public String getName() { return name; }
Access Modifiers Non - Access Modifiers //setter method
public void setName(String name) { = name; }
Scope Private Default Protected Public Type Scope }
public class Show{
Same class Yes Yes Yes Yes
Static Makes the attribute dependent on a class public static void main(String[] args){
//creating instance of the encapsulated class
Same package subclass No Yes Yes Yes Artist s=new Artist();
Final Once defined, doesn’t allow any changes //setting value in the name member
Same package non-subclass No Yes Yes Yes s.setName(“BTS");
//getting value of the name member
Abstract Makes the classes and methods abstract
Different package subclass No No Yes Yes System.out.println(s.getName());
Different package non-subclass No No No Yes Synchronized Used to synchronize the threads }