Objects: Lecture #8 Manish Sinha
Objects: Lecture #8 Manish Sinha
Lecture #8
Manish Sinha
• What is an Object?
• What is a Class?
• Characteristics of Objects
• Constructors
• Cookie Cutters
• Dot Notation
class stringTester {
public static void main ( String[] args ) {
String str1; // str1 is a variable that refers to an object,
// but the object does not exist yet.
int len; // len is a primitive variable of type int
str1 = new String(“Amitabh Bachchan"); // create an object of type
//String
len = str1.length(); // invoke the object's method length()
System.out.println("The string is " + len + " characters long");
}
}
3. The second String will get the characters " and ham."
String bat = new( "A shot rang out in the dark." ); Wrong--
new needs a constructor name.
Questions ?
manish[AT]cse.iitb.ac.in
http://www.cse.iitb.ac.in/~manish