new_Keyword

new Java Keyword with Examples

The new keyword is used to create a new instance of a class.
The new Java Keyword Examples
The new keyword is used to create a new instance of a class.
Student student = new Student(“Tom”, 20);
The new keyword can be used to create a new array object:
// use the new keyword to create an int array object
int[] intArray = new int[10];
The new keyword can be used to create a new String array object:
// use the new keyword to create a String object
String string = new String();
Complete Example

package com.javaguides.corejava.keywords.newkeyword;

/**
 * Demonstrates the usage of new keyword
 * @author Ramesh Fadatare
 *
 */
public class NewKeyword {

    public static void main(String[] args) {

        // use new keyword to create custom object type
        Student student = new Student("Tom", 20);

        // use new keyword to create int array object
        int[] intArray = new int[10];

        // use new keyword to create String object
        String string = new String();

        // use new keyword to create instance of Object
        Object object = new Object();
    }

}

class Student {
    private String name;
    private int age;
    public Student(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }
}
全部评论

相关推荐

沉淀一会:1.同学你面试评价不错,概率很大,请耐心等待; 2.你的排名比较靠前,不要担心,耐心等待; 3.问题不大,正在审批,不要着急签其他公司,等等我们! 4.预计9月中下旬,安心过节; 5.下周会有结果,请耐心等待下; 6.可能国庆节前后,一有结果我马上通知你; 7.预计10月中旬,再坚持一下; 8.正在走流程,就这两天了; 9.同学,结果我也不知道,你如果查到了也告诉我一声; 10.同学你出线不明朗,建议签其他公司保底! 11.同学你找了哪些公司,我也在找工作。
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务