zoukankan      html  css  js  c++  java
  • 主方法

    public class TestExample {     public static void main(String[] args) {   new TestExample().print();  }

     private   void print() {          System.out.println("HelloWorld");    }  

    }    这样在print方法时没有static所以就应该使用实例化对象来调用非static方法,    所有的非static方法几乎都有一个特点:方法要由实例化对象调用

    class Book{  private static int count=0;  private String title;  public String getTitle() {   return this.title;  }  public Book(){   this("NOTITLE-"+count++);  }  public Book(String title) {

        this.title=title;  } }  public class TestExample{   public static void main(String[] args) {   System.out.println(new Book().getTitle());   System.out.println(new Book("开发实战经典").getTitle());   System.out.println(new Book().getTitle());  } }

    总结很重要哦 方法得当,坚持会有奇迹哦
  • 相关阅读:
    stm32 IO模式
    stm32的ADC
    bsp
    stm32的硬件调试设置
    RTC实时时钟
    快手2019笔试题 “回文子串" 解题思路
    C++内存修改器开源代码
    FC游戏修改教程(hack)小白文。
    GLFW+GLEW搭建opengl环境(备忘)
    8086 IO读写操作
  • 原文地址:https://www.cnblogs.com/sunyuhuan/p/7269340.html
Copyright © 2011-2022 走看看