java modifies the use of class methods and use tips of share

  • 2020-05-27 05:48:21
  • OfStack

This paper mainly explains the use method and attention points of decoration class. In java programming, decoration class is mainly used to enhance the methods of existing classes. It is not possible to change the source code of a project in practice.

/* Decorative design mode 
 *  When you want to enhance the functionality of an existing object, 
 *  You can define classes, pass in existing formations, build on existing capabilities, and provide enhancements. 
 *  Then the custom class is called the decorator class 
 *  A decorator class simply enhances an existing class. The premise is that you have to have this class. */

import java.util.*;

class Chifan{
public void chifan(){
System.out.println(" breakfast ");
class SuperChifan{
private Chifan chifan2=null;
SuperChifan(Chifan chifan2){
public void superchifan(){
System.out.println(" Playing CARDS ");
System.out.println(" drinking ");
System.out.println(" homework ");
System.out.println(" work ");
public class Decoration_1 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Chifan chifan1=new Chifan();
SuperChifan superchifan1=new SuperChifan(chifan1);


Related articles: