How to create a class that will produce a copy of another class object and cause its methods



  • How to create a class that will produce a copy of another class object and cause its methods. Thank you so much for answering the stupid question!



  • class Start{
    
    public static void main(String[] args){
    
     Cat cat; //переменная для хранения экземпляра
    
     cat = new Cat(); //сам экземпляр класса Cat мы поместили в переменную
    
     cat.method1(); //вызов метода 
    
     }
    
    }
    
    class Cat{
    
     void method1()
     {
      System.out.println("I am Cat!");
     }
    
    }
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2