function Engine(size) { var privateVar; function privateMethod () { //... } this.publicMethod = function () { // with access to private variables and methods }; this.engineSize = size; // public 'field' } function Car() { // generic car this.engine = new Engine(); } function BMW1800 () { this.engine = new Engine(1800); } BMW1800.prototype = new Car(); // inherit from Car var myCar = new BMW1800();
public class EngineServlet extends HttpServlet { private Engine engine; // init is the "official" place for initialisation public void init(ServletConfig config) throws ServletException { super.init(config); engine = new Engine(); }
function Engine(){ // this is constructor. Empty since Engine do nothing. } Engine.prototype.EngineSize=null; // this is public property function Car(){ // this is Car constructor. It initializes Engine instance and stores it in Engine public property this.Engine =new Engine(); } Car.prototype.Engine =null;
//new Engine(); Engine engine = new Engine(); frame.add(engine); frame.setVisible(true);
function Engine(){};//emtpy Engine.prototype.i = 0; var newEngine = new Engine(); console.log(newEngine.i);//0 var anotherEngine = newEngine(); newEngine.i = 1234; console.log(anotherEngine.i);//0 console.log(newEngine.i);//1234
class Benz extends Car { Benz() { super(new Engine()); } }
class Car { private Engine engine; public Car() { engine = new Engine(); } }
public class Vehicle { private Engine; public void crankIgnition(){ engine = new Engine("6 Liter Engine"); engine.startEngine(); System.out.println("Vehicle is running"); } }
@Override public Engine onLoadEngine() { final Display defaultDisplay = getWindow().getWindowManager().getDefaultDisplay(); CAMERA_WIDTH = defaultDisplay.getWidth(); CAMERA_HEIGHT = defaultDisplay.getHeight(); this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera)); }
public Car(){ engine = new Engine() body = new Body() tank = new GasTank() transmission = new Transmission() }
function Engine() { this.EngineSize=1600; } function Car() { this.engine=new Engine(); } var myCar=new Car();
public class Vehicle { public void crankIgnition(){ Engine sixLiterEngine = new Engine("6 Liter Engine"); sixLiterEngine.startEngine(); System.out.println("Vehicle is running"); } }
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { new Engine().go(); } }); }
public class EngineServlet extends HttpServlet { private Engine engine = new Engine(); // does this make sure engine only gets instantiated one time in the entire lifespan of the web application; from what I've read from the servlet lifecycle, it seems like it, but I'd like to hear opinions public void doGet(HttpServletRequest request, HttpServletResponse response) { String text = request.getParameter("text"); ResultBean result = engine.run(text); request.setAttribute("result", result); RequestDispatcher dispatcher = request.getRequestDispatcher("result.jsp"); dispatcher.forward(request, response); // what's the difference between forward, and request.sendRedirect() ? } }
List<Car> cars = new ArrayList<Car>(Arrays.asList(new Car("C0"), new Car("C1"), new Car("C2"))); cars.get(0).setEngines(new ArrayList<Engine>()); cars.get(1).setEngines(new ArrayList<Engine>()); cars.get(2).setEngines(Arrays.asList(new Engine("C2E1"), new Engine("C2E2"), null)); cars.stream().filter(c -> Objects.nonNull(c.getEngines())).forEach(c -> { System.out.printf("Car %s ", c); c.getEngines().stream().filter(e -> Objects.nonNull(e) && Objects.nonNull(e.getParts())).forEach(e -> { System.out.printf(" Engine %s ", e); e.getParts().stream().filter(p -> Objects.nonNull(p)) .forEach(p -> System.out.printf("Part %s", p)); }); System.out.println(); });
public class Main { public static void main(String[] args) { final Chassis chassis = new Chassis(2000); final Engine engine = new Engine(3000); final Transmission transmission = new Transmission(4000); final Car car = new Car(1000, chassis, engine, transmission); System.out.println(chassis.toString()); } }
Engine engine = new Engine(); InputHandlerSystem ihs = new InputHandlerSystem(); RawInputHandler rih = RawInputHandler(); rih.registerListener(ihs); engine.addSystem(ihs); enigne.addSystem(new PlayerMovementSystem());
public Engine mapEngineShared(ResultSet rs) throws SQLException { Engine engine = new Engine(); engine.setId("ENGINE_ID"); // Aliased from "ID" engine.setId("ENGINE_MODEL_TYPE"); // Aliased from "MODEL_TYPE" return engine; }
@RequestMapping(value = "/submitAdmissionForm.html", method = RequestMethod.POST) public ModelAndView submitAdmissionForm(@RequestParam("volume") float volume, @RequestParam("model") String model) { ModelAndView modelView = new ModelAndView("AdmissionSuccess"); Engine engine = new Engine(); engine.setVolume(volume); Car car = new Car(); car.setEngine(engine); car.setModel(model); modelView.addObject("msg", "Details submited by you: Volume: " + car.engine.getVolume() + " Model: " + car.getModel()); return modelView; }
Engine eng1 = new Engine("abc"); Car car1 = new Car(); car1.setEngine(eng1); //here you have set the reference eng1 which is pointing to the object abc in heap Car car2 = new Car(); car2.setEngine(car1.getEngine());// here you are getting the reference of the object which is in the heap and setting it in car2 Object