码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA学习(2)&&一些感想

时间:2016-05-25 00:15:41      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

主要学习了JAVA语言中父类,子类,抽象(abstract)的概念,书上讲了通过抽象一个Person类,然后派生出Employee和Student类,同时对抽象函数进行了重新定义,使得派生出的类不是抽象类。

package abstractClasses;

public class PersonTest
{
	public static void main(String[] args)
	{
		Person[] people=new Person[2];
		people[0]=new Employee("harry",20000,1989,12,10);
		people[1]=new Student("ron","computer science");
		for(Person p:people)
		{
			System.out.println(p.getName()+","+p.getDescription());
		}
	}
}

  

package abstractClasses;

public abstract class Person
{
	public abstract String getDescription();
	private String name;
	
	public Person(String n)
	{
		name=n;
	}
	public String getName()
	{
		return this.name;
	}
}

  

package abstractClasses;
public class Student extends Person
{
	private String major;
	public Student(String n,String m)
	{
		super(n);
		major=m;
	}
	public String getDescription()
	{
		return String.format("a student majors in "+major);
	}
}

  

package abstractClasses;

import java.util.Date;
import java.util.GregorianCalendar;
public class Employee extends Person
{
	private double salary;
	private Date hireDay;
	public Employee(String n,double s,int year,int month,int day)
	{
		super(n);
		salary=s;
		GregorianCalendar calendar=new GregorianCalendar(year,month-1,day);
		hireDay=calendar.getTime();
	}
	public Date getHireDay()
	{
		return hireDay;
	}
	public double getSalary()
	{
		return salary;
	}
	public String getDescription()
	{
		return String.format("an employee with a salary of $%.2f",salary);
	}
	public void raiseSalary(double percent)
	{
		this.salary*=(1+percent);
	}
}

  

最近两天因为刷了几道算法题,没有学太多JAVA的知识,发现关于《Core Java》这本书看的进度有点太慢了,并且还有很多其他东西想做(分布式,C++,游戏引擎,web安全等等),推掉了所有的感觉提升不了自己实力的项目,还有一年时间就是实习生招聘的时间,目标是能够进一个满意的公司去实习,谁知道呢,谁说我就进不了MS呢!虽然前面一年半浪费了不少时间,但是感觉学了不少算法和数据结构,也算上是一种提升吧,往后还是会继续刷ACM的题目的,毕竟算法这东西需要积累!不过我不会再太在意绩点之类的,感觉也没什么用,顺其自然就好,专业方面的考试课好好准备就行,英语也不能放掉!明年要是我找不到满意的实习,就去准备考研。

 

JAVA学习(2)&&一些感想

标签:

原文地址:http://www.cnblogs.com/northsnow95/p/5525442.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!