编写一个学生类 java类TestClass

随便定义一个类TestClass和一个接口TestInterface。_百度知道
随便定义一个类TestClass和一个接口TestInterface。
TestInterface t =
(TestInterface) new TestClass();这样写为什么不报错误,TestClass和TestInterface之间没有implements。
我有更好的答案
因为你用了强制类型转换!就是(TestInterface) 进行了强转!
哦,对啊,只在运行时报异常,谢啦,突然一阵迷糊。
采纳率:36%
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。豆丁微信公众号
君,已阅读到文档的结尾了呢~~
java基础练习题,写一个class类有几个参数构造方法再把写入内容显示出来
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
java基础练习题,写一个class类有几个参数构造方法再把写入内容显示出来
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='http://www.docin.com/DocinViewer--144.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口(小练习)编写一个Student类,代表学生
编写一个Student类,代表学生。
具有属性:姓名,年龄,其中年龄不能小于16岁,否则输出错误信息
具有方法:自我介绍,负责输出该学生的姓名,年龄。
编写测试类StudentTest 进行测试,看是否符合要求
在学生类中的SetAge()方法中验证年龄的大小
在测试类总分别测试学员的年龄小于16岁,大于16时的输出结果
public class Student{//1.成员变量private S//2.构造器//3.成员方法public void intruction(){System.out.println("我叫" + this.name + ",年龄" + this.age);}public void setName(String name){this.name =}public String getName(){return this.}public void setAge(int age){if(age & 16){System.out.println("年龄太小了");}this.age =}public int getAge(){return this.}
public class StudentTest{public static void main(String[] args){Student1 stu = new Student1();stu.setName("张三");//stu.setAge(12);stu.setAge(16);stu.intruction();}
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!急:(懂的人救命啊)编写一个完整的Java Application 程序。包含类Student、TestStudent拜托各位大神_百度知道
急:(懂的人救命啊)编写一个完整的Java Application 程序。包含类Student、TestStudent拜托各位大神
.编写一个完整的Java Application 程序。包含类Student、TestStudent,具体要求如下: Student类 : ① 属性: name : String对象,表示一个人姓名 sex: char类型,用来表示性别 id:long类型,表示学号 classinfo:String对象,表示班级 address :String对...
我有更好的答案
public class Student{ private S private S private S public void Student(String name,char sex,long id){ this.name= this.sex= this.id= } public String getName(){ return this. } public void setId(long id){ this.id= } public void setAddress(String add){ this.address= } public void setClass(String classinfo){ this.classinfo= } public String toString(){ return (&姓名:&+name+&性別:&+sex+&學號:&+id+&班級:&+classinfo+&地址:&+address+&\n&); } } public class TestStudent{ public static void main(String args []){ Student objStu=new Student(&張三&,'男',12); objStu.setAddress(&地球&); objStu.setClass(&xx6班&); system.out.println(&objStu.toString()&); } }
采纳率:69%
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。每一个优秀的人背后都有一段默默努力的时光
使用类反射写一个自己的Junit Test
import java.lang.annotation.ElementT
import java.lang.annotation.R
import java.lang.annotation.RetentionP
import java.lang.annotation.T
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface MyJUnit {
import java.lang.reflect.InvocationTargetE
import java.lang.reflect.M
import java.util.S
public class RunJUnit {
public static void main(String[] args) {
System.out.println("请输出你需要测试的类: ");
Scanner scanner = new Scanner(System.in);
String path = scanner.nextLine();
Class&?&clazz = Class.forName(path);
Object obj = clazz.newInstance();
Method[]methods = clazz.getDeclaredMethods();
for (Method method : methods) {
if(null != method.getAnnotation(MyJUnit.class)) {
method.invoke(obj);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
scanner.close();
public class TestMyJUnit {
public void test1() {
System.out.println("");
public void test2() {
System.out.println("22");
public void test3() {
System.out.println("3");
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!}

我要回帖

更多关于 编写程序定义类point 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信