You are on page 1of 3
Class and Object x Instance Methods Vehicle class Instances Bus Cars Van Class and Objects © Aclass is a structure that defines the attributes and methods to work on the data. © An instance is an executable copy of a class, 7 Coss engine: Engine | color : Gotor ftacceerate(v Velocity) Instance, Attibutes, ‘and Method In the given snippet, Name and AssociatelD are the attributes of the class Label. Snippet of a program: public class Label { char Name; har AssociatolD; Public char getName( }{ return Name; } Public void setName, )f Name = newName;} ‘class will have a constructor by default. This constructor is responsible for creating @ new object. Example Label myLabel = new Label(|; Sample Program ‘An example for classes and objects, class Test {int a= 5; b= 10; } class print { public static void main (String aras{]) { Test Objectt = new Test0); ‘System.out prntin( “Value A + Objectt.a); System.out prntin( "Value B =" + Objectt.b}; } d Check Your Understanding Which Is an executable cogy of a class? oo @ ° Method Attribute Object Data Summary In this session, you have learned that: © Acless is a structure that defines the attributes and methods to work on the data © An object is an instance of a class

You might also like