2024 08 02 - Class and Object
2024 08 02 - Class and Object
to
Programming
Object and Class, Data types, Basic
I/O
TYPES OF PROGRAMMING
● Computers convert text and other data into binary by using an assigned ASCII
value.
● Once the ASCII value is known that value can be converted into binary.
Assembly language
● The Java Bytecode Assembler (or simply Assembler) is a program that converts
code written in "Java Assembly Language" into a valid Java.class file
MOV - move data from one location to The following assembly language can be
another used to add the numbers 3 and 4:
ADD - add two values
SUB - subtract a value from another mov eax,3 -loads 3 into the register
value "eax"
PUSH -push data onto a stack mov ebx,4 -loads 4 into the register
POP - pop data from a stack "ebx“
JMP - jump to another location
INT - interrupt a process add eax,ebx,ecx-adds "eax" and "ebx" and
stores the result (7) in "ecx"
Procedural-Oriented language
What is Object?
● In real-world an entity that has state and its behavior is known as an object.
● For Example:
✔ A Car is an object. It has states (name, color, model) and its behavior (changing gear, applying
brakes).
What is Class?
● A class is a template or blueprint that is used to create objects.
● Class representation of objects and the sets of operations that can be applied to
such objects.
● A class consists of Data members and methods.
DEFINING A CLASS IN JAVA
Syntax: ` Example:
public class class_name public class Car
{ {
Data Members; public:
Methods; double color;
} double model;
}
CLASS MEMBERS
● Using Class.forName()
MyObject object = (MyObject) Class.forName("subin.rnd.MyObject").newInstance();
● Using clone()
MyObject anotherObject = new MyObject();
MyObject object = (MyObject) anotherObject.clone();
Example:01 Example:02
public class MyClass { public class MyClass {
int x = 5; int x = 5;
MyClass.java OtherClass.java
public class MyClass { class OtherClass {
int x = 5; public static void main(String[] args) {
} MyClass myObj = new MyClass();
System.out.println(myObj.x);
}
}
3 WAYS TO INITIALIZE OBJECT
1. By reference variable
2. By method
3. By constructor
3 WAYS TO INITIALIZE OBJECT
Example:01 Example:02
Class Test {
public static void main(String[] args) {
Test obj = new Test();
obj.start();
}
void start() {
String stra = "do";
String strb = method(stra);
System.out.print(": " + stra + strb);
}
String method(String stra) {
stra = stra + "good";
System.out.print(stra);
return " good";
}
}
QUESTION : 01
A. X only
B. Y only
C. Both X and Y are correct
D. Both X and Y are incorrect Answer:
C
QUESTION : 02
A. 1 only
B. 2 only
C. 1 & 2
D. 3 & 4 Answer:
B
QUESTION : 05
Answer:
B
QUESTION : 10
Answer:
C
QUESTION : 11
Answer:
C
QUESTION : 12
Answer:
B
QUESTION : 18
Answer:
D
QUESTION : 20
A. Variables
B. Objects
C. Methods
D. Operators
Answer:
B
QUESTION : 21
A. Method
B. Keyword
C. Class
D. Variables
Answer:
C
QUESTION : 22
A. 4 8
B. 4 4 Answer:
C. 8 4
D. 8 8 A
QUESTION : 23
A. 4 8
B. 4 4 Answer:
C. 8 4
D. 8 8 A
QUESTION : 24
A. 4 8
B. 4 4 Answer:
C. 8 4
D. 8 8 B
QUESTION : 25
System.out.println(""+st1.name+""+st1.marks+""+st1.section)
;
System.out.println(""+st2.name+""+st2.marks+""+st2.sect
ion);
} A. Rajesh 87 C Rajesh 87 C
} B. rajesh 87 C rajesh 87 C Answer:
C. Rajesh C 87 Rajesh C 87
A
D. rajesh C 87 rajesh C 87
QUESTION : 26
Answer:
QUESTION : 28
Answer:
A
QUESTION : 30
A. i=1
B. i = 103 Answer:
C. i = 55 B
D. Compilation Error
QUESTION : 32
A. a=0a=0
B. a=1a=1 Answer:
C. a=0a=1
D. a=1a=2 B
E. Compilation Error
QUESTION : 33
A. 5
B. Compile time Error since no default constructor
C. Compile time Error since no parameterized constructor
D. Compilation Error or Runtime Error for some other Answer:
reason C
QUESTION : 38
X: These are different types of inner classes - Nested top-level classes, Member
classes, Local classes, Anonymous classes.
Y: If the main method is declared as private then the program compiles properly
but at run-time it gives a message conveying "Main method is not public."
A. X only
B. Y only
C. X and Y
D. Both are incorrect Answer:
QUESTION : 39
A. 20 20 25
B. 20 30 25
C. Compilation Error
D. Runtime Error Answer:
QUESTION : 40
A. 20
B. 25
C. Compilation Error
D. Runtime Error Answer:
OUR PRODUCT
Aptimithra
aptimithra.co
m
Google Review
ethnus.com
THANK YOU