0% found this document useful (0 votes)
2 views3 pages

JavaAssessment6 Answers

The document is an assessment for Java programming, consisting of multiple-choice questions, output questions, and programming tasks. It covers various topics such as object-oriented programming concepts, method overriding, and class structures. Additionally, it includes code examples for constructor overloading, area calculation, and interface implementation.

Uploaded by

gragavan2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

JavaAssessment6 Answers

The document is an assessment for Java programming, consisting of multiple-choice questions, output questions, and programming tasks. It covers various topics such as object-oriented programming concepts, method overriding, and class structures. Additionally, it includes code examples for constructor overloading, area calculation, and interface implementation.

Uploaded by

gragavan2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JAVA PROGRAMMING – ASSESSMENT

Duration: 2 Hours

Maximum Marks: 100

1. b) ==

2. b) length()

3. c) Array stores elements of the same data type.

4. b) extends

5. c) private

6. c) Scanner sc = new Scanner([Link]);

7. b) interface

8. a) charAt()

9. b) continue

10. c) Abstraction

11. The default case in a switch statement executes when none of the case values match the
switch expression.

12. The Scanner class is used to read input from the user or other input sources. For example,
Scanner can read integers, strings, and other data types from [Link].

13. A multidimensional array is an array containing arrays, commonly used to represent data in
rows and columns. Syntax: int[][] arr = new int[rows][columns];

14. Method overriding occurs when a subclass provides its own implementation of a method
that is already defined in its parent class, using the same method signature.

15. An object is an instance of a class. It represents a real entity and contains state (data) and
behaviour (methods) defined by the class.
16. The == operator compares two values or references for equality, while the = operator
assigns a value to a variable.

17. Runtime polymorphism is the process where the method to be executed is determined at
runtime, usually through method overriding and a parent-class reference referring to a child-
class object.

18. a) Variable: final makes a variable constant, so its value cannot be reassigned after
initialization. b) Method: final prevents a method from being overridden by a subclass.

19. Three commonly used String methods are length(), charAt(), and substring().

20. A class is a blueprint or template that defines data and methods. An object is an actual
instance created from that class.

PART C – OUTPUT QUESTIONS


21. Output: 2 4 6

22. Output: gram

23. Output: 15

24. Output: 13

25. Output: Child

PART D – PROGRAMS
26. Constructor Overloading – Employee Class

class Employee {
int id;
String name;

Employee() {
[Link]("Employee Created");
}

Employee(int id, String name) {


[Link] = id;
[Link] = name;
[Link]("Employee ID: " + id);
[Link]("Employee Name: " + name);
}

public static void main(String[] args) {


Employee e1 = new Employee();
Employee e2 = new Employee(101, "Arun");
}
}
27. Rectangle Class – Calculate Area

class Rectangle {
double length;
double breadth;

Rectangle(double length, double breadth) {


[Link] = length;
[Link] = breadth;
}

double calculateArea() {
return length * breadth;
}

public static void main(String[] args) {


Rectangle r = new Rectangle(10, 5);
[Link]("Area = " + [Link]());
}
}
28. Interface Animal – Dog Implementation

interface Animal {
void sound();
}

class Dog implements Animal {


public void sound() {
[Link]("Dog barks");
}

public static void main(String[] args) {


Dog d = new Dog();
[Link]();
}
}

You might also like