×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: Mar 7, 2021 12:41 PM
Views: 4772
Tags: oo
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         /* There are 3 ways to intialize instace variables
  8.     1. At the time of declaration
  9.     2. Method
  10.     3. From main class using reference variables
  11.   */
  12.  
  13. //2. Methode
  14.         //NachteiL: bei 1000 Objekten: Viel zu viel Arbeit!
  15.         /*
  16.         Car c = new Car();
  17.         c.initialize("Model S", "Red", 4);
  18.  
  19.         Car c1 = new Car();
  20.         c1.initialize("Model S2", "Black", 4);
  21.  
  22.         c.display();
  23.         c1.display();
  24.          */
  25. //3. und beste Methode
  26.         //Variablen müssen public sein!
  27.         //Nachteil: Code wird lang
  28.    /*     Car c = new Car();
  29.         c.model = "Model S";
  30.         c.color = "Red";
  31.         c.seats = 4;
  32.  
  33.         Car c1 = new Car();
  34.     */
  35.  
  36.     }
  37.  
  38. }
  39.