Moving taxi item 1

// can only use a class name and file name consistent
// module Andri Export
// define a class to call in outside
public class HelloJava
{// main method
 public static void main (String args [])
 {
  System.out.printIn ( " Java hello ")
 }

}
return shell open a thread executing a.out return the return value is returned to the shell
calss Dog
{
 Dog(){
 this.color = "black"
 }
 Dog(String color){
  this.color = color
 }
public void sleep(){
 System.out.println(this.color + "Dog is sleep");
}
private String color;
}

public class Text2_demo
{
 public static void main(String args[]){
 Dog dog1 = new Dog();
 Dog dog2 = new Dog("dahuang");
 dog1.sleep();
 }
}

Value is passed c / c ++ value passed to open up new space
are passed by value java python basic types of delivery, complex type references
different byte, long double, boolean, char , by way of explanation
type of application: new out all references
 
Test3 {class
 // static constant type common
 public static final String content = "AC "
}
public class Text3
{
 public static void main(String args[]){
  System.out.println(test3.content);
  test3 t = new test3();
  System.out.println(t.content);
  t.content = "123";
  System.out.println(t.content);
 }
}
public class Test4_static{
 
 private int a = 0;
 public static void main(String args[]){
 }
}

c / c ++: class declare variables
java: can be defined in a statement
The method of this pointer is not static;
default: files are available in the current
final constants
on the left can not be signed.
instanof
public class

class Hero{
 public void attack(){
  System.out.println("attack");
 }
}
Inherited
class Yase the extends Hero {
 // method overrides
 public void Attack () {
  System.out.println ( "")
 }
}
public class Test_externts()
{
     public static doAttack(Hero hero){
      if (hero instanceof Yase){
       System.out.println("yes");
      }esle if(hero instanceof Libai)
      {
       System.out.println("LIBAI");
      }
      hero.attack();// 多态
     }
     public static void main(String args[]){
      Hero hero = new Hero();
      hero.attack();
      Hero y = new Yase();
      y.attack();
      Hero l = new LiBai();
      l.attack();
 
     }
}
Static method: class method

public class Test_Array{
 public static void printArray(int[] array){
  for(int item: array){
   System.out.println(item);
  }
 }
 //  二维数组
 public static void printArray2(int..arry)
 {
  for(int i; i< array.length;i++)
  {
   System.out.println(array[i])
  }

 }
 
 Public static void main (String args []) {
  int [] = {1,2,3,4,5} array1; // define an array
  int [] array2 = new int [ 5]; // reference
 }
}
  Array name pointer values normally

  Combination:
  class SON1
  {
   SON1 (Fathor FA)
   {
    this-> FA = FA;
   }
   Private:
    Fathor * FA;
  }
  inheritance:
  class Son: public Fathor
  {
  }
导入包  
  import java.util.Date;
  public class Test_date{
   public static void main(String args){
    Date date = new Date();
    System.out.println(date.toString());
   }
  }
 Time: system time
 localtime: Local Time
 Format Time:

 import java.util.*
 public class Test7{
  public static void main(String args[]){
   try{
    System.out.println(new Date()+"\n");
    Thread.sleep(1000*3);
    System.out.println(new Date()+"\n");
   the catch} (Exception E) {
    System.out.println ( "Exception Gat AN");
   }
  }
 }
--------------------------- --------------------
// default inherit Object
class Hero {
 
 Hero (String name) {
  this.name = name;
 }
 // can not modify rights
 protected void finalize ( ) {
 }
 Private String name;
}
// not a timing recovery
 public class Test7 {
  static void main public (String args []) {
   Hero H = new new Hero ( "Gailun");
// call display recovering
  H = null;
  // performed manually
  System.gc ();
  }
 }
 -------------------------------
 public class Test7{
  public static void main(String args[]){
   char[]  strArray = {"A","B","C"};
   String str1 = new String(strArray);
   String str2 = new String("abc");
   String str3 = "xye";
   String str4;
   str4 = String.format("%f,%d,%s",3.14,100,"itcast")
   System.out.println(str4);
  }
 }
 ----------------------------
 import java.io. *
 the Test class {public
  
  public static void main (String [] args) {
   byte [] = {1,2,3,4,5} binary;
   // file output stream of the process stream to flow out of
   the try {
    the OutputStream new new OS = a FileOutputStream ( " test.txt ");
   for(int i=0;i<binary.length; i++){
    os.write(binary[i]);
   }
   os.close();

   InputStream is = new FileInputStream("test.txt");
   int size = is.available();
   for(int i=0;i< size;i++){
    System.out.print(is.read()+",");
   }
   is.close();
   }catch(IOException e){
   System.out.println("io error");
   }
   
  }
 }
 hexdump: View binary representation
 00000000 (address) 020104030005
 00000005 (address)
-------------------------------- -----
abstract class
class Animal{
 public void move(){
 System.out.print("")
 }
}
class Dog extends Animal{
 
 public void move(){
  super()
  super.move();  // 第一个父类
  System.out.print()
 }
}
主方法
public class TestDog{
 public static void main(String[] args){
 }
}

Has virtual functions
abstract class Animal {
 abstract void EAT ();
 String name; // attribute
}
class Dog extends Animal{
 Dog(String name){
  this.name = name;
 }
 System.out.print(this.name + "sleep");

}
class Test{
 public static void show(Animal animal){
  animal.eat();
  if(animal instanceof Dog){
   Dog d = (Dog)animal;
   d.eat();
  }else if(animal instanceof Cat){
   Cat c = (Cat)animal;
   c.eat();
  }
 }
 public static void main(String []args){
  Animal cat = new Cat("Tom");
  Animal dog = new Dog("Big");
  show(cat);
  show(dog);
 }
}
---------------------------
interface Fight{
 public void attack();
 public void skill();
}
interface Action{
 public void run();
 public void die();
}
abstract Hero{
 Hero(Sting name){
 this.name = name;
 }
 public abstrack void kill();
 private String name;
}
Implement the extends Gailun Fight Hero class, the Action {
 Gailun () {
  Super ( "gailun");
 }
 // implement the interface
 public void Attack () {}
 public void skill () {}
 public void RUN () {}
 public void Die ( ) {}
 // implement the abstract method
 public void kill () {
  this.run();
  this.attack();
  this.skill();
 }

}
---------------------
mkdir Animals
Animal.java
Package Animals; // current module
interfaces
public interface Animal {
 public void EAT ();
 public void SLEEP ();
}
--------------------
VSP Cat.java
package animals;
public class Cat implements Animal{
 public void eat()
 {
  System.out.print("hhh");
 }
}

wq:
A package: an abstract class, the entity class two
-----------------------
import animals.Animal;
import animals.cat
import animals.Dog
public class Test{
 public static void main(String args[]){
  Animal dog = new Dog();
  Animal Cat = new Cat();
  
 }
}

Guess you like

Origin www.cnblogs.com/countryboy666/p/11570269.html