Академический Документы
Профессиональный Документы
Культура Документы
As a language
that has the object-oriented feature, Java supports
the following fundamental concepts:
Polymorphism
Inheritance
Encapsulation
Abstraction
Will be discussed on a
Classes
different chapter.
Objects
Instance
Method
Message Parsing
Object
Objects have states and behaviors. An object is an
instance of a class.
Example: A dog has states/properties – color,
name, breed as well as behaviors – wagging,
barking, eating.
Class
A class can be defined as a template/blue print
that describe the behaviors and states/properties
that object of its type support.
public class Dog {
Class
String breed;
int age;
String color; States/Properties
void barking(){
} Behaviors
void hungry(){
}
void sleeping(){
}
}
Random rand = new Random();
Scanner scan = new
Scanner(System.in);
String msg = new String();
Equivalent to String msg;
public getAge(){
System.out.println("Puppy's age is: " + puppyAge );
return puppyAge;
}
public static void main(String []args){
/*Object creation*/
Puppy myPuppy = new Puppy("tommy");