131, Java Object-oriented static keyword of three (defined using the static method)

01. code is as follows:

Package TIANPAN; 

class Book {                                 // describe the same publishing information 
    Private String title;
     Private  Double . price;
     Private  static String Pub = "University Press";      // Define a description attribute information publishing 

    public Book ( title String, Double . price) {
         the this .title = title;
         the this .price = . price; 
    } 

    public  static  void setPub (String P) {             // definition of static methods can be called directly by the class name 
        Pub = P; 
    }

    public String getInfo () {
         return "Book Name:" + the this .title + ", the price:" + the this .price + ", publishing house:" + the this .pub; 
    } 
} 

/ ** 
 * Documentation Comments here 
 * 
 * @author Tin Pan micro-channel 382 477 247
  * / 
public  class TestDemo {
     public  static  void main (String args []) { 
        Book.setPub ( "University Press");             // call generated when no object 
        Book BA = new new Book ( "the Java development", 10.2);         // instantiate an object class Book 
        Book BB = new newBook ( "the Android Development", 11.2);     // instantiate an object class Book 
        Book BC = new new Book ( "the Oracle development", 12.2);     // instantiate class object Book 
        System.out.println (ba.getInfo ()) ; 
        System.out.println (bb.getInfo ()); 
        System.out.println (bc.getInfo ()); 
    } 
}

 

02. Results are as follows:

 

 

Knowledge has a price, if you think this article valuable, authors agree to pay, micro-channel two-dimensional code can be any amount of a reward to the author (Micro Signal: 382 477 247) Oh, thank you.

Guess you like

Origin www.cnblogs.com/tianpan2019/p/12337343.html