Files
JavaIntermediate/MoreOnClasses/src/main/java/com/oop/Main.java
2024-09-27 10:23:15 +02:00

65 lines
1.9 KiB
Java

package com.oop;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int a = read.nextInt();
Pupil pupil = new Pupil();
pupil.setAge(a);
Standard standard1 = new Standard();
Pro pro1 = new Pro();
//standard version
standard1.draw();
standard1.write();
//Pro version
pro1.draw();
pro1.write();
pro1.useEffects();
pro1.changeResolution();
//Polymorphism
// Vehicles can be classified according to what energy source powers them. The program you are given has 3 vehicle classes: Vehicle, ElectricVehicle and HybridVehicle.
// ElectricVehicle and HybridVehicle classes are inherited from Vehicle class.
// Complete the program by reimplementing method resource() in inherited classes, so that the given calls work correctly.
Vehicle vehicle = new Vehicle();
Vehicle electric = new ElVehicle();
Vehicle hybrid = new HybridVehicle();
//calls
vehicle.start();
vehicle.resource();
electric.start();
electric.resource();
hybrid.start();
hybrid.resource();
//overriding funcions! For more visit Program.js
System.out.println(Program.max(8, 17));
System.out.println(Program.max(3.14, 7.68));
//Overloading or overriding
a = 5;
double b = 10.2;
System.out.println(doubleTheValue(a));
System.out.println(doubleTheValue(b));
}
//complete the method for integer value type
public static int doubleTheValue(int a) {
return a*2;
}
//overload the method for double value type
public static double doubleTheValue(double a) {
return a*2;
}
}