public class Main {
public static void main(String[] args) {
Cat cat = new Cat();
cat.setName("Vasyka");
Dog dog = new Dog();
dog.setName("Barbos");
Human human = new Human();
human.setCat(cat);
human.setDog(dog);
System.out.println(human.getDog().voice());
System.out.println(human.getCat().voice());
}
}
interface Animal {
String voice();
}
abstract class Pet implements Animal {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class Dog extends Pet {
@Override
public String voice() {
return getName() + " says Woof";
}
}
class Cat extends Pet {
@Override
public String voice() {
return getName() + " says Meaw";
}
}
class Human {
private Pet cat;
private Pet dog;
public Pet getCat() {
return cat;
}
public void setCat(Pet cat) {
this.cat = cat;
}
public Pet getDog() {
return dog;
}
public void setDog(Pet dog) {
this.dog = dog;
}
}
public class Main {
public static void main(String[] args) {
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("person.dat", false))) {
Person p = new Person("Sam", 33, 178, true);
Person p2 = new Person("John", 40, 165, false);
oos.writeObject(p);
oos.writeObject(p2);
} catch(Exception ex) {
System.out.println(ex.getMessage());
}
try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream("person.dat"))) {
Person p = (Person) ois.readObject();
System.out.println(p.getName());
System.out.println(p.getAge());
System.out.println(p.getHeight());
System.out.println(p.getMarried());
Person p2 = (Person) ois.readObject();
System.out.println(p2.getName());
System.out.println(p2.getAge());
System.out.println(p2.getHeight());
System.out.println(p2.getMarried());
} catch (Exception e) {
e.fillInStackTrace();
}
}
}
javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call
/**
* Allocates a new {@code Thread} object. This constructor has the same
* effect as {@linkplain #Thread(ThreadGroup,Runnable,String) Thread}
* {@code (null, null, name)}.
*
* @param name
* the name of the new thread
*/
public Thread(String name) {
init(null, null, name, 0);
}
Thread(null, "Дочерний поток # ");
@param target the object whose run() method gets called
/**
* If this thread was constructed using a separate
* <code>Runnable</code> run object, then that
* <code>Runnable</code> object's <code>run</code> method is called;
* otherwise, this method does nothing and returns.
* <p>
* Subclasses of <code>Thread</code> should override this method.
*
* @see #start()
* @see #stop()
* @see #Thread(ThreadGroup, Runnable, String)
*/
@Override
public void run() {
if (target != null) {
target.run();
}
}