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());  } }

    总结很重要哦 方法得当,坚持会有奇迹哦
  • 相关阅读:
    置换笔记
    7.23
    Conveyor Belts
    CF #134 A~D
    Blocks && Fixing the Great wall
    Kakuro
    Deadlock Detection
    关于KeyFile的破解,含注册机源代码
    BMP位图之代码实现
    BMP位图之8位位图(三)
  • 原文地址:https://www.cnblogs.com/sunyuhuan/p/7269340.html
Copyright © 2011-2022 走看看