zoukankan      html  css  js  c++  java
  • java12类的无参方法

    package com.jh.test01;
    
    public class AutoLion {
    	
    	// 属性: 颜色 黄色
    	String color = "黄色";
    	
    	// 函数:跑,叫;
    	// 跑
    	public void run() {
    		System.out.println("跑得很快哦");
    	}
    	
    	// 叫
    	public String bark() {
    		return"吼--叫";
    	}
    	/*
    	 * 获取颜色的函数。
    	 */
    //	if(true) {
    //		
    //	}
    	public String getColor() {
    //		return "黄色";
    		return color;
    	}
    //	
    //	public String showLion() {
    //		
    //		return "这是一个"+color+"颜色狮子";
    //	}
    
    	public String showLion() {
    		
    		return "这是一个"+getColor()+"颜色狮子";
    	}
    	
    	
    }
    

      

    package com.jh.test01;
    
    public class AutoLionTest {
    	public static void main(String[] args) {
    		// 创建键盘录入对象.
    		AutoLion al = new AutoLion();
    		// 调用跑的函数
    		al.run();
    		// 调用吼叫的函数
    		
    		// 带返回值的函数通常是赋值调用.
    		String bark = al.bark();
    		System.out.println(bark);
    		
    		System.out.println("**************");
    //		System.out.println(color);
    		System.out.println(al.color);
    		
    		// 调用getColor()函数,获取color属性值
    		String color = al.getColor();
    		System.out.println(color);
    		// 调用showLion()函数
    		System.out.println(al.showLion());
    	}
    
    }
    

      

    package com.jh.test01;
    
    public class Student {
    	
    	// a函数
    		public void aa() {
    			System.out.println("aaaaaaaa");
    		}
    		
    		// b函数
    		public void b() {
    			// 调用 a函数。
    			aa();
    			System.out.println("bb");
    
    }
    }
    

      

    package com.jh.test01;
    
    public class Teacher {
    	// a函数
    	public void a () {
    		System.out.println("aaaaaaa");
    	}
    	
    	// b函数
    	public void b () {
    		
    		// 想在这里调用Student类里面的aa()函数
    //		aa();// 不能直接调用
    		// 创建Student对象,然后,.调用
    		Student stu = new Student();
    		stu.aa();
    		System.out.println("bbb");
    }
    }
    

      

    package com.jh.test01;
    
    public class jh_函数使用中常见的错误 {
    //	System.out.println("helloworld");
    //	public static void main(String[] args) {
    //		System.out.println();
    //	}
    	int age = 18;
    //	public void info() {
    //		return "xiaojiejie";
    //		方法的返回值类型为void,方法中不能有return 返回值!
    //	}
    	
    //	public int  getInfo() {
    //		
    //		int a = 5;
    //		int b = 3;
    //		return a,b;
    //		方法不能返回多个值!
    //	}
    	
    //	public void a () {
    //		public void b() {
    //			多个方法不能相互嵌套定义!
    //		}
    //	}
    	
    //	不能在方法外部直接写程序逻辑代码!
    //	if(a>0) {
    //		age = a;//加限定条件。
    //	}// 业务逻辑
    	public void setAge() {// getColor
    		int a = -19;
    //		age = a;//加限定条件。
    		if(a>0) {
    			age = a;//加限定条件。
    		}// 业务逻辑
    		System.out.println();
    
    }
    }
    

      

  • 相关阅读:
    浅尝EffectiveCSharp_6
    浅尝EffectiveCSharp_7
    浅尝EffectiveCSharp_9
    CLR_via_C#.3rd 翻译[1.6 框架类库]
    浅尝EffectiveC#_11
    CLR_via_C#.3rd 翻译[1.9 与非托管代码的操作]
    wcf学习笔记_2(修改wcf配置文件)
    CLR_via_C#.3rd 翻译[1.4.2 不安全代码]
    CLR_via_C#.3rd 翻译[1.4.1 IL与验证]
    CLR_via_C#.3rd 翻译[1.8 通用语言规范]
  • 原文地址:https://www.cnblogs.com/weiamd/p/11199709.html
Copyright © 2011-2022 走看看