Professional Documents
Culture Documents
Johane Grei C. Dingding - Bsit 2C Syntax: Class Car (
Johane Grei C. Dingding - Bsit 2C Syntax: Class Car (
OBJECT: CAR
class Car {
String brandcar;
public void Status() {
System.out.println("\n\n>>State\n\n");
System.out.println("Running");
System.out.println("PARK");
System.out.println("\n\nBEHAVIOR: DRIVE");
System.out.println("BEHAVIOR: FORWARD");
System.out.println("BEHAVIOR: REVERSE");
System.out.println("BEHAVIOR: SHIFT");
System.out.println("BEHAVIOR: CHANGE GEAR");
System.out.println("BEHAVIOR: HAZARD");
class act1 {
public static void main(String[] args) {
Normalcar.brandcar = "Mercedes";
Normalcar.Status();
// create an object of the subclass
luxurycar.brandcar = "Mercedes";
luxurycar.Status();
Explanation:
The code uses the concept of Inheritance by using the
keyword extends. Inheritance is an important pillar of OOP
(Object-Oriented Programming). It is the mechanism in java by
which one class is allowed to inherit the features (fields and
methods) of another class. ... The subclass can add its own fields
and methods in addition to the superclass fields and methods.
The child class SportsCar inherits the features(fields and
methods) of the parent class which is the Car.
CONCEPT: ENCAPSULATION
OBJECT: LAPTOP
class laptop{
laptop = newLaptop;
}
public String getLaptop() {
return laptop;
brand = newBrand;
return brand;
}
public void setStatus(String newStatus) {
status = newStatus;
return status;
behavior = newBehavior;
}
public String getBehavior() {
return behavior;
class act1encap {
obj.setLaptop("\nLaptop-Macbook");
System.out.println(obj.getLaptop());
obj.setBrand("\nApple");
System.out.println(obj.getBrand());
obj.setStatus("\nSTATUS: on/off");
System.out.println(obj.getStatus());
obj.setBehavior("\nBEHAVIOR: Typing");
System.out.println(obj.getBehavior());
System.out.println(obj.getBehavior());
System.out.println(obj.getBehavior());
obj.setBehavior("\nBEHAVIOR: Print Documents");
System.out.println(obj.getBehavior());
System.out.println(obj.getBehavior());
}
Explanation:
The code uses the concept of Encapsulation by using
Encapsulation; the code was able to hide the values or state of a
structured data object inside a class, preventing unauthorized
parties' direct access to them. By declaring the objects; laptop,
brand, behavior, status as private, it prevents the data from being
accessed by the code outside this shield. The program also uses
Getters and Setters, Getters and Setters play an important role in
retrieving and updating the value of a variable outside the
encapsulating class. A setter updates the value of a variable,
while a getter reads the value of a variable.