关于java的instanceof类型转换

Java中接口(instance)和继承(extends)与抽象(abstract)的区别与联系详细说明 阅读详情

关于java的instanceof类型转换

我们在上一篇文章中了解到了java比较重要的特性多态,本篇文章,承接上一篇文章中的伏笔,一起来了解一下instanceof类型转换,引用类型之间的转换😀。

一、instanceof

  • 判断一个对象是什么类型。
  • 判断两个类之间是否存在父子关系。

1、我们先创建三个类,人类,老师类,学生类,并在人类中写出一个run方法。

package oop.Demo08;
//Person
public class Person
{
    public void run()
    {
        System.out.println("run");
    }
}
package oop.Demo08;
//Student
public class Student extends Person
{
    
}
package oop.Demo08;
//Teacher
public class Teacher extends Person
{
    
}

2、我们用main方法,来使用一下instanceof。

import oop.Demo08.Student;
import oop.Demo08.Teacher;

public class Application {
    public static void main(String[] args)
    {
        //Object > String
        //Object > Person > Teacher
        //Object > Person > Student
        Object object = new Student();

        System.out.println(object instanceof Object);
        System.out.println(object instanceof Person);
        System.out.println(object instanceof Student);
        System.out.println(object instanceof Teacher);
        System.out.println(object instanceof String);//因为Object和String有联系
    }
}

我们执行以下代码,会看到以下的结果。

true
true
true
false
false

因为instanceof是判断是否存在父子类关系,我们的Teacher,和学生类是平级,所以不存在关系,String类型是引用类型,也不能作为关系的对比,就像猫不等于狗。

import oop.Demo08.Student;
import oop.Demo08.Teacher;

public class Application {
    public static void main(String[] args)
    {
        //Object > String
        //Object > Person > Teacher
        //Object > Person > Student
        Person person = new Student();

        System.out.println(person instanceof Object);
        System.out.println(person instanceof Person);
        System.out.println(person instanceof Student);
        System.out.println(person instanceof Teacher);
        //System.out.println(person instanceof String);//没有关联,编译器会报错
    }
}
true
true
true
false

我们再来看一个Student对象。

import oop.Demo08.Student;
import oop.Demo08.Teacher;

public class Application {
    public static void main(String[] args)
    {
        //Object > String
        //Object > Person > Teacher
        //Object > Person > Student
        Student student = new Student();

        System.out.println(student instanceof Object);
        System.out.println(student instanceof Person);
        System.out.println(student instanceof Student);
        //System.out.println(student instanceof Teacher);//没有关联,编译器会报错
        //System.out.println(person instanceof String);//没有关联,编译器会报错
    }
}
true
true
true
  • 公式:X instanceof Y
  • 编译是否可以通过,取决于X和Y有没有关联,有没有父子关系😎。

二、类型转换

我们在Student类中,写一个go方法,现在的Student类中有自己的go方法和父类的run方法。

package oop.Demo08;

public class Student extends Person
{
    public void go()
    {
        System.out.println("go");
    }
}

我们之前了解过,基本类型转换,由高转低,需要强转,但是低转高,不需要强转。

关于java的基本类型转换

  • 类型之间的转化:父子转换

  • 父比子高,所以不需要强制转换。

public class Application {
    public static void main(String[] args)
    {
        Person person = new Student();//Person类型
    }
}

但是我们想使用学生类中的go方法,由于学生类是低类型,Person是高类型,所以需要强制转换。

public class Application {
    public static void main(String[] args)
    {
        Person person = new Student();//Person类型
        ((Student) person).go();
    }
}

也可以用下面的方法,清晰一些。

public class Application {
    public static void main(String[] args)
    {
        Person person = new Student();
        Student student=(Student) person;
        student.go();
    }
}
  • 由低转高,不需要强转。
public class Application {
    public static void main(String[] args)
    {
        Student student = new Student();
        Person person=student;
    }
}
  • 子类转换为父类,可能丢失自己原本的方法。

三、总结

  • 父类的引用指向子类的对象。
  • 子类转换为父类,向上转型不用强制转换。
  • 想把父类转换为子类,向下转型,需要强制转换,可能会丢失方法。
  • 转换方便方法调用,不用重新new一个类,通过降级等使用类中的方法,减少重复的代码,有效提供利用率。
  • 抽象:封装,继承,多态。
  • 抽象类:比抽象还要抽象的🥲(我们放在后续的文章中详细说明)。
  • 接口:比抽象类还要抽象的🥲(我们放在后续的文章中详细说明)。
  • 编程的思想其实就是围绕抽象,所以我们要做到持续的学习,现在学习以后可能不会理解的很透彻,但是不断积累,不断实践,多多对自己的想法进行一个验证,有一天可能遇到一个问题,解决了,突然茅塞顿开。
java中的instanceof 关键字以及作用 2)instanceof关键字的作用是判断左边对象是否是右边类的实例-(通俗易懂来说就是左边的对象是否是右子类对象。或者右边类本身的对象)返回的boolean对象,是就是true,不是就是false。1)instanceof是java中的一个关键字,java中的关键字都是小写字母。1)使用instanceof增加了代码的灵活性。 阅读详情

相关推荐

【项目实战】优化if-else逻辑之使用多个instanceof

if语句中的多个instanceof

奶爸的编程之路,也就一周冷个三天 1127

Java Instance(实例)的创建过程

默认初始化:内存分配完成后,JVM 会将内存区域中的所有实例变量初始化为默认值,包括父类和子类的变量。实例变量的定义处初始化:在类的定义中,如果为某些实例变量赋予了初始值(在定义时赋值),这些赋值操作会在父类构造方法执行完毕并返回后执行,初始化父类的字段。然后子类构造方法中的初始化操作会继续进行,初始化子类的字段。

goTsHgo的博客 1984

深入理解Java中的instanceof和类型转换

本文深入探讨了Java中的instanceof运算符和引用类型转换。通过示例代码和分析,解释了在运行时如何通过instanceof判断对象是否是某个类或接口的实例,以及何时可以安全地进行类型转换。同时,讨论了泛型对instanceof运算符的影响,并提供了使用instanceof的正确方式和类型转换的注意事项。

weixin_34392511的博客 284

《深入理解 Java 中的 Instance(实例)》

在 Java 中,一个实例(instance)通常指的是一个具体的对象,是通过类的构造函数创建出来的特定的实体。每个实例都具有自己独立的状态和行为。例如,我们定义一个名为Personint age;通过以下方式创建一个Person这里的person就是一个Person类的实例,它具有自己独立的name和age属性值,并且可以调用introduce方法来展示自己的信息。Java 中的实例是面向对象编程的核心概念之一。

m0_72256543的博客 3566

SAP 资产主数据屏幕增强:对比字段追加与子屏幕/页签 2 种方案优劣

本文深入对比了SAP资产主数据(AS01/AS03)屏幕增强的两种方案:字段追加与子屏幕/页签。从技术实现、业务适配、系统维护等维度分析各自优劣,提供方案选型决策树和混合方案实践建议,帮助企业在SAP实施中做出最优选择。

weixin_28559803的博客 283

Unity——Scroll View 滑动居中、居中的放大、其他的缩小(支持横竖Scroll View)

一、效果 二、上代码,两种方式。 (第一种是在Update中用插值完成的,如果不想再项目中看到Update,下面的另一种改了一段用DoTween实现的,需要导入一下DoTween) using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Unit...

SiReSo 7659

Java instanceof和类型转换

instanceof和类型转换 X instanceof Y 判断X和Y是否有父子关系,如果有的话为ture,没有的话为false Object->Person->Student Object->Person->Teacher Object->String Object object = new Student(); System.out.println(object instanceof Student);//true

qq_44730435的博客 504

论文阅读4——一种宽频带圆极化微带天线的设计

论文阅读——一种宽频带圆极化微带天线的设计(现在才觉得开始弄懂了一点,懂了一点之后又更糊涂了……)

weixin_64612422的博客 2316

java的instanceof和强制类型转换

instance of和类型转换 1.instance of是什么? instance of 这个关键字可以判断两个类之间是否存在父子关系。 2.怎么使用instanceof? 咱们开始之前要先建立四个程序,这个四个程序可以弄明白他的原理。 person类(父类) public class person { } student类(子类) public class student extends person { } teacher类(子类) public class teacher

m0_60996938的博客 2069

使用蒙特卡洛模拟方法在MATLAB中估算居里温度: 一个详细而通俗的指南

居里温度是磁性材料失去磁性的温度。但是,计算机模拟为我们提供了一个在理论和实验之间的桥梁,使我们能够在不进行实际测量的情况下估计这一重要参数。在下一部分,我们将详细介绍蒙特卡洛迭代的核心代码,以及如何使用它来模拟磁性材料中原子的行为。在估算居里温度的上下文中,我们将使用蒙特卡洛方法来模拟磁性材料中的原子或分子的行为。通过使用蒙特卡洛方法,我们可以在MATLAB中估算居里温度,从而为理论研究和实验设计提供有价值的信息。:我们使用的是一个有限的尺寸的网格模型,这可能导致一些大小效应,特别是在接近居里温度时。

qq_38334677的博客 977

【Simulink教程案例18】基于simulink的基础OFDM+64QAM发射接收链路仿真

OFDM(Orthogonal Frequency Division Multiplexing)即正交频分复用技术,实际上OFDM是MCM(Multi Carrier Modulation),多载波调制的一种。通过频分复用实现高速串行数据的并行传输, 它具有较好的抗多径衰落的能力,能够支持多用户接入。OFDM技术由MCM(Multi-Carrier Modulation,多载波调制)发展而来。OFDM技术是多载波传输方案的实现方式之一,它的。

FPGA/MATLAB学习教程/源码/项目合作开发 1984

【JAVA-Day66】深度解析Java显式类型转换与instanceof关键字

在Java中,显式类型转换(Explicit Type Casting)是指程序员明确地将一个数据类型转换为另一个数据类型的过程。这种转换需要通过强制转换操作符来完成,通常涉及从一个较大的数据类型到一个较小的数据类型。类型转换运算符是用于执行类型转换的运算符,例如强制类型转换(type)。// 强制类型转换精彩的旅程就在类型转换的海洋中展开!在Java这片广袤的领域里,深刻理解和熟练运用类型转换机制是成为高效开发者的关键一步。希望你在这篇技术博客中找到了有价值的信息,并能够在类型转换的世界里畅游自如。

沉淀所学,分享所思,让热爱与成长同行。商务记录AI实战经验,助力开发者快速成长。 热爱AI,希望做出有影响力的技术成果。 技术点亮生活,分享连接价值与机会。 专注AI落地实战,陪你走好技术每一步。 1万+

【Matlab】matlab代码实现sph溃坝模拟

本文介绍了一个基于MATLAB的SPH溃坝模拟实现。代码使用平滑粒子流体动力学方法,通过建立1000个随机分布的粒子,计算粒子间的相互作用力来模拟流体运动。模拟过程包括初始化参数、粒子创建、密度压力更新、速度位置计算以及可视化展示。核心算法采用poly6Kernel和spikyKernelGradient函数处理粒子间作用力。该示例为二维简化模型,仅包含基本物理参数和计算流程,实际应用需进一步优化扩展。

unber的博客 206

Java 16 instanceof模式匹配来了:你还在用传统类型转换?

Java 16 instanceof 模式匹配简化类型判断与转换,告别冗长代码。在条件判断中直接声明变量,提升可读性和安全性,适用于各类对象类型处理场景。代码更简洁,错误更少,开发效率更高,值得收藏。

PixelIsle的博客 847

3、利用预训练卷积神经网络进行特征提取

本文介绍了如何使用预训练的卷积神经网络(如VGG16)进行图像特征提取,并将提取的特征存储在HDF5数据集中,以便后续用于机器学习模型的训练。文章详细阐述了特征提取的原理、HDF5数据格式的优势、HDF5DatasetWriter类的实现、特征提取流程的代码实现以及实际应用案例。通过该方法,可以在多种图像数据集上高效构建高精度的分类模型。

z2a3b4c5d的博客 112

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

【java基础】instanceof和类型转换

什么是instanceof instanceof 是 Java 的保留关键字。它的作用是测试它左边的对象是否是它右边的类的实例,返回 boolean 的数据类型。 public class Application { public static void main(String[] args) { //Object > String //Object > Person > Teacher //Object > Person

m0_45290871的博客 455

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Java自学|instanceof和类型转换

Java自学|instanceof和类型转换 1.概念 instanceof关键字可以去判断两个类之间是否有父子关系 如果一个对象时某个特定类或者时该特定类的子类的一个实例那么就返回真 不能对两个没有直接向上关系的类进行如此操作(编译直接报错) 格式:实例 instanceof 类 Person person = new Person(); System.out.println(person instanceof Person); 2.实例 我们先定义一个Person类 //基类 public

Alan_Lowe 228

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

java学习笔记45--instanceof和类型转换

例如: public class Person{ public void run(){} } public class Student extends Person{ } public class Teacher extends Person{ } 例如: main: Obje...

onepiece_loves的博客 206

instanceof和类型转换(Java基础)

instanceof和类型转换 instanceof 判断类型是否相似,只要有继承关系,instanceof就为true 例子: //父类 package oop.dome9; public class Person{ public void run(){ System.out.println("run"); } } //子类 package oop.dome9; public class Student extends Person{ public void g

weixin_43704586的博客 227

Java instanceof关键字与类型转换

大家好,今天来分享一下instanceof关键字和类型转换 instanceof是Java的一个保留关键字,判断一个对象的是什么类型, 判断两个类是不是父子关系,左边是对象,右边是类,返回类型是Boolean类型。它的具体作用是测试左边的对象是否是右边类或者该类的子类创建的实例对象,是的话,则返回true,否则返回false。 创建Person类 package Demo03; public class Person { } 创建student类 ,继承于Person package Demo

weixin_47556601的博客 858

Java面向对象:instanceof, 类的强制类型转换,static关键字

在我们使用多态时,创建的对象引用类型为父类,无法调用子类特有的方法,此时,我们通过强制类型转换将引用类型转换为子类,而instanceof关键字可用于判断能否强制类型转换。如果一个类中的方法全都是使用 static 声明的静态方法,我们就可以通过import static的方式进行导入,这种导包方式就叫做静态导入。静态代码块不能直接访问非静态成员(实例变量、实例方法),但可以访问静态成员(静态变量、静态方法)。静态代码块是 Java 类在加载过程中执行的一段代码,静态代码块在类第一次被加载时执行,并且。

2302_80199430的博客 1483

Java面向对象:instanceof和类型转换

instanceof instanceof可以判断一个类的实例是否继承于另外一个类 TestExtends.java package BasicGrammar; public class TestExtends { public static void main(String[] args) { A a = new A(); System.out.println(a instanceof A);//True System.out.println(a

天行健 君子以自强不息,地势坤 君子以厚德载物。 463

Java :多态、instanceof、类型转换

一、多态 主要包含测试文件、父类文件Person1、子类文件Teacher1 //Application package com.MA; import com.MA.operator.demo3duotai.Person1; import com.MA.operator.demo3duotai.Teacher1; public class Application { public static void main(String[] args) { Teacher1 t

qq_53208462的博客 626

Java中instanceof与类型转换

Java中instanceof与类型转换 1.新建Person类 public class Person { public void run(){ System.out.println("run"); } } 2.新建Student类 public class Student extends Person { public void go(){ System.out.println("go"); } } 3.新建Teacher类 p

qq_47897078的博客 308

Java-instanceof与类型转换

/* instanceof其实是java的一个二元操作符, 和=,<,>这些是类似的,同时它也是被保留的关键字. 主要的作用,是为了测试左边的对象,是不是右边的类的实例,返回的是boolean值。 */ public class Application { public static void main(String[] args) { //Object -> Person -> Teacher //Object -> String

qishi45的博客 197
上一篇: 关于java的多态
下一篇: 关于java中static详解
落满樱花的羊
博客等级 码龄5年 1021粉丝 54原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值