@koustuvsinha/

GoldInsignificantCrow

Java

No description

fork
loading
Files
  • Main.java

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.747371077048179","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"Y2xhc3MgVmVoaWNsZSB7CglwdWJsaWMgdm9pZCBzdGFydCgpIHsKCQkvLyBzdGFydGluZyB0aGUgZW5naW5lCgkJU3lzdGVtLm91dC5wcmludGxuKCJzdGFydGluZyB0aGUgZW5naW5lLi4uIik7Cgl9CgoJcHVibGljIHZvaWQgc3RvcCgpIHsKCQkvLyBzdG9wcGluZyB0aGUgZW5naW5lCgkJU3lzdGVtLm91dC5wcmludGxuKCJzdG9wcGluZyB0aGUgZW5naW5lLi4uIik7Cgl9Cn0KCmNsYXNzIENhciBleHRlbmRzIFZlaGljbGUgewoJaW50IG51bWJlck9mU2VhdHMgPSA0OwoKCXB1YmxpYyBpbnQgZ2V0TnVtYmVyT2ZTZWF0cygpIHsKCQlyZXR1cm4gbnVtYmVyT2ZTZWF0czsKCX0KfQoKY2xhc3MgQmlrZSBleHRlbmRzIFZlaGljbGUgewoJaW50IG51bWJlck9mU2VhdHMgPSAyOwoJCglwdWJsaWMgdm9pZCBraWNrU3RhcnQoKSB7CgkJU3lzdGVtLm91dC5wcmludGxuKCJraWNrc3RhcnRpbmcuLi4iKTsKCX0KfQoKY2xhc3MgTWFpbiB7CiAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgQ2FyIGNhciA9IG5ldyBDYXIoKTsKCVZlaGljbGUgdmVoaWNsZSA9IGNhcjsgLy8gdXBjYXN0aW5nCglDYXIgY2FyMiA9IChDYXIpdmVjaGlsZTsgLy9kb3duY2FzdGluZwoJCglCaWtlIGJpa2UgPSBuZXcgQmlrZSgpOyAvLyBzYXkgQmlrZSBpcyBhbHNvIGEgc3ViY2xhc3Mgb2YgVmVoaWNsZQoJVmVoaWNsZSB2ID0gYmlrZTsgLy8gdXBjYXN0aW5nLCBubyBwcm9ibGVtIGhlcmUuCglDYXIgY2FyMyA9IChDYXIpYmlrZTsgLy8gQ29tcGlsYXRpb24gRXJyb3IgOiBhcyBiaWtlIGlzIE5PVCBhIGluc3RhbmNlIG9mIENhcgogIH0KfQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Vehicle {
	public void start() {
		// starting the engine
		System.out.println("starting the engine...");
	}

	public void stop() {
		// stopping the engine
		System.out.println("stopping the engine...");
	}
}

class Car extends Vehicle {
	int numberOfSeats = 4;

	public int getNumberOfSeats() {
		return numberOfSeats;
	}
}

class Bike extends Vehicle {
	int numberOfSeats = 2;
	
	public void kickStart() {
		System.out.println("kickstarting...");
	}
}

class Main {
  public static void main(String[] args) {
    Car car = new Car();
	Vehicle vehicle = car; // upcasting
	Car car2 = (Car)vechile; //downcasting
	
	Bike bike = new Bike(); // say Bike is also a subclass of Vehicle
	Vehicle v = bike; // upcasting, no problem here.
	Car car3 = (Car)bike; // Compilation Error : as bike is NOT a instance of Car
  }
}