java之葵花宝典

java之葵花宝典importjava util Arrays importjava util Scanner author 男神许老师 2020 年 1 月 1 日 classStudent publicintage publicString publicStuden System ou

import java.util.Arrays; import java.util.Scanner; / * */ / * @author 男神许老师 *2020年1月1日 * */ //class Student{ 
    // public int age; // public String name; // public Student() { 
    // System.out.println("this is a student"); // } // public Student(String name) { 
    // this(); // this.name=name; // } //  //} //public class new1 { 
    // public static void main(String[] args) { 
    // Scanner sc=new Scanner(System.in); // //面向对象程序设计三大特性:封装、继承、多态 // //java中可以通过this调用已经存在的构造方法 //  // Student a=new Student(); // Student b=new Student("许远志"); // System.out.println(a.name); // System.out.println(b.name);  int a;  while(sc.hasNext()) { 
     a=sc.nextInt();  System.out.println(2<<a-1); // }  double a=10.0;  final int b=5;//java 中使用关键字final来定义常量  // System.out.println(3==5);  // b=20;  int arr[]= {2};//静态初始化  int arr1[]=new int[1];//动态初始化 // // arr1=arr; // // arr1[0]=2; //  // //基本数据类型比较直接比较数值,引用数据类型比较直接比较地址 // // System.out.println(arr.equals(arr1)); // //equals 可以只可以比较引用数据类型,方法可以重写 // //==既可以比较基本数据类型又可以比较引用数据类型 // // System.out.println(arr[0]==arr1[0]);  int arrays[][];//二维数组  Arrays.sort(arr);  System.out.println(arr[1]);  System.out.println(Arrays.binarySearch(arr,2)); // //值传递不会改变参数的值  int a=3;  System.out.println("改变之前:"+a);  tri(a);  System.out.println("改变之后:"+a);  //引用传递会改变参数的值  int arr[]= {1,2,3};  System.out.println("改变之前:"+Arrays.toString(arr));  fun(arr);  System.out.println("改变之后:"+Arrays.toString(arr)); 方法重载:同一个类中两个或以上的同名方法,参数类型,个数或顺序不同,称为方法的重载 // }  public static void tri(int a) { 
     a=a*3;  }  public static void fun(int arr[]) { 
     for(int i=0;i<arr.length;i++) { 
     arr[i]+=1;  } // } //} //继承 //一个类只能有一个直接基类 //final 修饰的类不能有派生类,String 是典型特例 class Student{ 
    public int age; public String name; public Student(int age,String name) { 
    this.age=age; this.name=name; } public void print() { 
    System.out.println("你好"); } } //派生类内不能访问基类中private修饰的属性或方法 class BigStudent extends Student{ 
    public String major; public BigStudent() { 
    super(25,"龟男");//调用基类的构造方法,可以有参数也可以无参数 //super 用于引用基类中的属性或方法super.属性,super.方法 //this 用于引用本类中的属性或方法 this.属性,this.方法 this.major=super.name; } //派生类对基类中定义的方法进行重新实现称为方法重写 //重写只能出现在继承之中 public void print() { 
    System.out.println("啦啦啦"); } } public class new1 { 
    public static void main(String[] args) { 
    Student a=new Student(12,"嘴男"); Student b=new BigStudent(); // System.out.println(a.age+b.age); // System.out.println(a.name+b.name); // System.out.println(b.major); a.print(); b.print(); } } 
 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/232734.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java class加载机制及对象生成机制

    java class加载机制及对象生成机制

    2022年2月23日
    38
  • pip 更新matplotlib「建议收藏」

    pip 更新matplotlib「建议收藏」pip更新matplotlib命令:pipinstallmatplotlib–upgrade–user加–user是由于很多python包是安装在C盘中,去做更改时需要管理员权限。

    2025年5月26日
    1
  • 程序,进程,线程的区别和联系

    程序,进程,线程的区别和联系进程和程序区别和联系表现在以下方面:1)程序只是一组指令的有序集合,它本身没有任何运行的含义,它只是一个静态的实体。而进程则不同,它是程序在某个数据集上的执行。进程是一个动态的实体,它有自己的生命周期。它因创建而产生,因调度而运行,因等待资源或事件而被处于等待状态,因完成任务而被撤消。反映了一个程序在一定的数据集上运行的全部动态过程。2)进程和程序并不是一一对应的,一个程序执行在不同的数据集上…

    2022年7月15日
    13
  • MATLAB函数调用

    MATLAB函数调用数学建模matlab自定义函数时间2020年5月10日学习Matlab自定义函数使用,并结合所学函数简单修改了一下上周的代码实现了Topsis法。1.Matlab语句构成的程序文件称为M文件,以m作为文件的扩展名,分为函数文件和程序文件。程序文件即脚本文件,无function;函数文件有function,且在第一行或者第一个不是注释的行2.两个文件运行函数:函数定义文件和函数调用文件(函数可在脚本文件或命令窗口直接调用),两文件必须放在同一目录下,函数文件名必须与函数名相…

    2022年7月17日
    20
  • apache2虚拟主机实现一个服务器绑定多个域名[通俗易懂]

    apache2虚拟主机实现一个服务器绑定多个域名[通俗易懂]1.apache2的配置首先要配置好apache2,如果未配置,请参考我之前的博文:lamp的配置2.域名的解析将全部域名的www和@的A记录解析到云服务器的IP3.虚拟主机的配置1.配置httpd.conf如果etc/httpd/conf/httpd.conf存在,则配置此httpd.conf如果etc/httpd/conf/httpd.conf不存在,此时需要我们在/etc/apache2下

    2022年9月18日
    1
  • Let’s Encrypt 申请HTTPS证书流程「建议收藏」

    Let’s Encrypt 申请HTTPS证书流程「建议收藏」准备工作:域名可供解析的服务器(或使用ngrok将需要生成证书的域名映射到具体的http服务器地址)申请官网地址:Let’sEncrypt、Certbot流程打开Certbot网址,选择使用服务器与操作系统,如下:使用如上命令在对应服务器安装好certbot后,使用:sudocertbotcertonly命令安装,certbot(实际上是certbot-au…

    2022年9月1日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号