PROGRAMMING

MINTE9
REMEMBERS




Last update:   26-07-2021

Classes

p9 ! In Java, everything goes into a class, in a file with .java extension. After compilation a new file with .class extension will be created.
 RunCode
/**
 * The main() method is where your program starts running.
 * The return type void means there is no returned value.
 * Every statement must end in semicolon.
 */

class App {

    public static void main(String[] args) {
        
        System.out.println("Hello Java!"); // Hello Java!
    }
} 
... 4 lines
˄˄˄

Object

p35 A class is a blueprint for an object. Fields (instance variables) is what an object knows, methods is what an object does.
 RunCode
class LearningApp {

    public static void main(String[] args) {
        
        MyClass obj = new MyClass();
        obj.setName("John");

        System.out.println("Hello " + obj.name); // Hello John
    }
}

class MyClass {

    public String name;
    
    public void setName(String name) {
        this.name = name;
    }
}
... 7 lines
˄˄˄

Questions    
2. Objects
01 . Classes
Last update:   26-07-2021

        A B C D E F
🔔
1/4