zoukankan      html  css  js  c++  java
  • Java面试集合(一)

    前言

    大家好,我是 Vic,今天给大家带来Java面试集合(一)的概述,希望你们喜欢

    1.Java按应用范围可划分几个版本?
    答:Java按应用范围有三个版本,分别是JavaSE,JavaEE,JavaME。

    2.Java有哪些特性?
    答:Java的特性有:面向对象,跨平台性,健壮性,安全性,可移植性,多线程性,等。

    3.带你走进Java的第一个编程题目?

    public class HelloWorld{
    public static void main(String[] args){
     System.out.println("Hello World");
    }
    }

    4.Java的基本数据类型?
    答:Java共有八种基本数据类型,分别是:

    byte,字节型,一个字节
    short,短整型,两个字节
    int,整型,四字节
    long,长整型,八字节
    float,单精度浮点型,四字节
    double,双精度浮点型,八字节
    char,字符型,两个字节
    boolean,逻辑值,一个字节

    5.打印奇数100内之和?

    public class One{
    public static void main(String[] args){
     int sum = 0; //定义总和变量
     for(int i = 1;i<100;i++){ //定义循环1到100的数
      if(i%2 != 0){ //如果i求余不等于0,得出奇数
         System.out.println(i);//打印i
         sum += i;
       }
     }

    6.排列数组,按顺序排列?

    public class Two{
       public static void main(String[] args) {
           int[] arr = { 4,51,2,7,6,9,8,10 };
           for (int i = 0; i < arr.length-1; i++) {
               //这里的算法可在Vic-深入浅出的排序算法进行相关复习
               for (int j = 0; j < arr.length-1-i; j++) {
                   if (arr[j] > arr[j + 1]) { // 比较相邻元素
                       int temp = arr[j];
                       arr[j] = arr[j + 1];
                       arr[j + 1] = temp;
                   }
               }
           }
           for (int i = 0; i < arr.length; i++) {
               System.out.print(arr[i] + " "); // 打印排序完后的元素
           }
       }
    }

    7.Java中的三大特性?
    答:Java中的三大特性,有继承,封装,多态。

    8.进行无参和有参的构造函数以及get,set方法,实例化代码描述?

    class Student {
       private String name;
       private int age;
       public Student() { //无参的构造函数
       }
       public Student(String name, int age) {  //有参的构造函数
           this.name = name;
           this.age = age;
       }
       public String getName() {
           return name;
       }
       public void setName(String name) {
           this.name = name;
       }
       public int getAge() {
           return age;
       }
       public void setAge(int age) {
           this.age = age;
       }
    }
    public class Three {
       public static void main(String[] args) {
           Student student = new Student(); //new一个对象
           stu1.setName("zhangsan");
           stu1.setAge(17);
           Student stu2 = new Student("lisi", 18);
       }
    }

    9.如何运用内部类?

    class My {
    class Mylove{
     public void loveYou() {
       System.out.println("I love U");
     }
    }
    }
    
    public class Four {
     public static void main(String[] args) {
       My.Mylove love = new My().new Mylove();
        love.loveYou();
    }
    }

    10.用代码表示继承关系?


    //定义父类
    class Person {
    String name;
    int age;
    Person() {
    System.out.println("Person的无参构造函数");
    }
    Person(String name, int age){
    this.name = name;
    this.age = age;
    System.out.println("Person的有参构造函数");
    }
    public void show(){
      System.out.println("name:"+name+",age:"+age);
    }
    }
    
    //定义子类继承父类
    class Student extends Person{
    public int id;
    public Student(){
     super();
     System.out.println("Student的无参构造函数"); 
    }
    public Student(String name, int age, int id){
     super(name,age);
     this.id=id;
    }
    public void show(){
     System.out.println("name:"+name+",age:"+age+",id"+id);
    }
    }
    
    //测试类
    public class Five{
    public static void main(String[] args){
     Person person = new Person("Vic",17);
     person.show();
     Student student = new Student("Vic",17,123456);
     student.show();
     }
    }
    总结
    • 本文讲了Java面试集合(一),如果您还有更好地理解,欢迎沟通

    • 定位:分享 Android&Java知识点,有兴趣可以继续关注

  • 相关阅读:
    A1039 Course List for Student (25 分)
    A1101 Quick Sort (25 分)
    日常笔记6C++标准模板库(STL)用法介绍实例
    A1093 Count PAT's (25 分)
    A1029 Median (25 分)
    A1089 Insert or Merge (25 分)
    A1044 Shopping in Mars (25 分)
    js 验证
    根据string获取对应类型的对应属性
    HTML 只能输入数字
  • 原文地址:https://www.cnblogs.com/dashucoding/p/11932694.html
Copyright © 2011-2022 走看看