This document discusses object-oriented programming (OOP) concepts like classes, objects, properties, and methods. It provides examples of creating classes in Java, instantiating objects from classes, and using constructors. It also demonstrates overloading constructors and the use of the 'this' keyword. Finally, it shows examples of using the File System Object in classic ASP to read from and write to text files.
17. ? //DriveAcar06.java
class Vehicle {
int numberOfWheels ;
boolean hasEngine ;
//constructor
Vehicle() {
numberOfWheels = 6 ;
hasEngine = true ;
System.out.println("A car has been built") ; // (1) notice this line
}
void run() {
System.out.println("I am running") ;
}
}
public class DriveAcar06 {
public static void main(String[] args) {
Vehicle myCar = new Vehicle() ;
System.out.println("mycar has "+myCar.numberOfWheels+"Wheels.") ; // (2)
System.out.println("That mycar has an engin is "+myCar.hasEngine+".") ; // (3)
}
}
19. ? //OverloadConstructor.java
class Vehicle {
int numberOfWheels ;
boolean hasEngine ;
//constructor and Overload Constructor
Vehicle() {
numberOfWheels = 6 ;
hasEngine = true ;
System.out.println("A car has been built") ; //notice this line
}
Vehicle(int number, boolean engine) { // (1)
numberOfWheels = number ;
hasEngine = engine ;
System.out.println("A car has been built") ; //notice this line
}
void run() {
System.out.println("I am running") ;
}
}
public class OverloadConstructor {
public static void main(String[] args) {
Vehicle myCar = new Vehicle(4,true) ; // (2)
System.out.println("mycar has "+myCar.numberOfWheels+"Wheels.") ;
System.out.println("That mycar has an engin is "+myCar.hasEngine+".") ;
}
}
20. ? //TestThis.java this()
class A {
int a ;
A() {
a=0;
System.out.println("Default constructor") ;
}
A(int i) {
this() ;
a=i;
System.out.println("constructor 1 ") ;
}
A(int i, int j) {
this(i+j) ;
System.out.println("constructor 2 ") ;
21. ? }
}
public class DriveAcar06 {
public static void main(String[] args) {
System.out.println("Instantiate x");
A x = new A() ;
System.out.println("Variable a is "+ x.a) ;
System.out.println("Instantiate y ");
A y = new A(5) ;
System.out.println("Variable a is "+ y.a) ;
System.out.println("Instantiate z ");
A z = new A(5,6) ;
System.out.println("Variable a is "+ z.a) ;
}
}
this()
23. ? static File System File System
File Access
? File Access Component
? Set Fso= CreateObject("Scripting.FileSystemObject")
? Fso
File Access Component Fso
? Open Text File Method
?
? Object.openTextFile(filename[,iomode][,create][,Format]
?
? Object