By GokiSoft.com|
07:51 24/03/2020|
Java Basic
Share Code- Bài giảng interface + static - C1907L
Source Code bài giảng
Tìm hiểu về lập trình OOP
- Hiểu về cách chuyển đổi 1 bài toán => lĩnh vực lập trình
Tính chất trong lập trình OOP
=> Tính chất đóng gói
=> Tính chất kế thừa
=> Tính đa hình
=> Tính trừu tượng
Kình nghiệm
=> Code được yêu cầu => chạy đc là OK
=> Tham khảo code của các anh chị đi trước + các bạn
=> Github
=> Hình thành nên tư code
===================================
- Xem lại => hỗ trợ & giải đáp cái gì => support
- Kiến thức mới
- Interface
=> Hieu interface la gi
=> Truong hop chung ta su dung interface la nhu nao
=> Cach su dung + code
=> OK => thanh cong vs interface
- Static
=> ???
- Test overview OOP
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lession5;
/**
*
* @author Diep.Tran
*/
public abstract class Animal implements IMoving{
String name, foodType;
public Animal() {
}
public Animal(String name, String foodType) {
this.name = name;
this.foodType = foodType;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFoodType() {
return foodType;
}
public void setFoodType(String foodType) {
this.foodType = foodType;
}
public abstract void showSound();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lession5;
/**
*
* @author Diep.Tran
*/
public class Cat extends Animal{
@Override
public void showSound() {
System.out.println("Meo ... meo ...");
}
@Override
public void moving() {
System.out.println("Mo ta chuyen dong cua Cat");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lession5;
/**
*
* @author Diep.Tran
*/
public class Dog extends Animal{
@Override
public void showSound() {
System.out.println("Go .. Go ..");
}
@Override
public void moving() {
System.out.println("Mo ta chuyen dong cua Dog");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lession5;
/**
*
* @author Diep.Tran
*/
public class Vehicle implements IMoving{
String name;
int wheel;
public Vehicle() {
}
public Vehicle(String name, int wheel) {
this.name = name;
this.wheel = wheel;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getWheel() {
return wheel;
}
public void setWheel(int wheel) {
this.wheel = wheel;
}
@Override
public void moving() {
System.out.println("Mo to chuyen dong cua Vehicle");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lession5;
/**
*
* @author Diep.Tran
*/
public class Citizen implements IMoving{
String name, address;
public Citizen() {
}
public Citizen(String name, String address) {
this.name = name;
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public void moving() {
System.out.println("Mo ta chuyen dong cua Citizen");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lession5;
/**
*
* @author Diep.Tran
*/
public interface IMoving {
//final => const
//static final => khai bao config (setting)
public static final int x = 12;
public static final int y = 15;
void moving();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lession5;
/**
*
* @author Diep.Tran
*/
public class Student {
public String name;
public static int AGE;
public Student() {
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lession5;
/**
*
* @author Diep.Tran
*/
public class Test {
public static void main(String[] args) {
Student stdA = new Student();
Student.AGE = 12;
Student stdB = new Student();
Student.AGE = 32;
System.out.println("A : " + Student.AGE);
System.out.println("B : " + Student.AGE);
Test test = new Test();
test.showMenu();
}
void showMenu() {
System.out.println("menu....");
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)