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

    总结很重要哦 方法得当,坚持会有奇迹哦
  • 相关阅读:
    Java8新特性详解
    RedisTemplate详解
    RestTemplate详解
    windows中将多个文本文件合并为一个文件
    commons-lang 介绍
    commons-cli介绍
    commons-collections介绍
    commons-codec介绍
    commons-beanutils介绍
    commons-io介绍
  • 原文地址:https://www.cnblogs.com/sunyuhuan/p/7269340.html
Copyright © 2011-2022 走看看