You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.8 KiB

Intro to Java

class HelloWorld{

	void printMessage() {
		System.out.println("Hi");
	}

	int add(int a, int b){
		return a + b;
	}

	void main(String[] args){

		//System.out.println("Hello, Matt");

		String greeting = "Hello there!";

		int myAge = 46;
		int myNewAge = myAge + 2;
		double myWeight = 144.5;
		//System.out.println(myWeight);

		Boolean isCool = false;
		if(isCool){
			//System.out.println("Welcome to the party");
		} else {
			//System.out.println("Get lost dweeeeeeb");
		}

		while(myAge < 50){
			//System.out.println(myAge);
			myAge++;
		}

		for(int i = 0; i < 5; i++){
			//System.out.println(i);
		}

		String[] cars = {"Volvo", "Toyota", "Mazda"};
		//System.out.println(cars[1]);

		//printMessage();

		int result = add(4, 2);
		//System.out.println(result);

		Human matt = new Human("Matthew");
		System.out.println(matt.name);

		SuperHuman superman = new SuperHuman("Clark", "flight");
		superman.name = "bilbo";
		System.out.println(superman.name);
		//superman.power = "burping";
		System.out.println(superman.getPower());

		Sedan myCar = new Sedan();
		myCar.drive();
		myCar.stop();

		Swallow stewart = new Swallow();
		stewart.fly();
	}

}
interface Bird {
	void fly();
}
abstract class Car {
	abstract void drive();
	void stop(){
		System.out.println("screeeeech");
	}
}
class Human {
	String name;
	Human(String name){
		this.name = name;
	}
}
class Sedan extends Car{
	void drive(){
		System.out.println("vroom");
	}
}
class SuperHuman extends Human {
	private String power;
	SuperHuman(String name, String power){
		super(name);
		this.power = power;
	}
	public String getPower(){
		return this.power;
	}
}
class Swallow implements Bird {
	public void fly() {
		System.out.println("sweeeee");
	}
}