Java中同一个对象只有调用了这个对象的某一个方法后才能使用这个对象其他方法怎么实现或设计?

比如一个电脑类,有一个开机方法,还有看视频,听音乐等方法,但是只有在开机后才能使用看视频,听音乐等方法,这样的如何实现?我试过放在构造函数里,但是感觉不能放在构造函数里,构造函数是创建对象了,相当于买电脑啊

可以用一个开关属性,为该属性提供一个 setter 方法。
再在其他方法中以该属性作为触发条件,只有该属性为真时,方法能继续,否则方法直接返回。例如:

public class Computer{
   private boolean isBoot;

     public Computer(boolean isBoot){
         this.isBoot = isBoot;
     }

     public Computer(){
     }

     public void setBoot(boolean isBoot){
        this.isBoot = isBoot;
     }

     public boolean openWord(){
        if(!isBoot){
               System.out.print("电脑未启动,不能执行后续操作");
                 return;
            }
            //TODO 继续执行后续逻辑
     }

     public static void main(String[] args){
        Computer c = new Computer();
            c.openWord();
            c.setBoot( true);//开机
            c.openWord();//开机后再次执行任务
     }
}

你可以先写一个方法,在方法里new一个对象,然后对象才生效,只有这个方法被执行了后那个对象才可以调用它的方法

可以使用静态构造函数来实现你的需求,并且这样可以提升语义,更加直观。
如果不想new一个新的对象,可以将这个改为单例模式。

public class Computer {
    // 将构造函数设为私有
    private Computer() {
    }
    public static Computer of() {
        return new Computer();
    }

    public void music() {
        System.out.println("听音乐");
    }

    public void video() {
        System.out.println("看视频");
    }

    public static void main(String[] args){
        Computer computer = Computer.of();
        computer.video();
        computer.music();
    }
}