oopsjavaASS2
oopsjavaASS2
NAME-RIYA DESHMANKAR
ROLL NO-2300290100212
SECTION-C
Person() {
name = "RiyaDeshmankar";
age = 20;
}
void display() {
System.out.println("Name is: " + name + ", age is " + age);
}
}
class Myclass {
public static void main(String[] a) {
Person obj = new Person();
obj.display();
}
}Output
Ques2) Write a Java program to create a class called "Dog"
with a name and breed attribute. Create two instances of the
"Dog" class, set their attributes using the constructor and
modify the attributes using the setter methods and print the
updated values.
class Dog {
String name;
String breed;
Dog() {
name = "max";
breed = "german shephard";
}
// Setter methods
public void setName(String name) {
this.name = name;
}
void display() {
System.out.println("Name: " + name + " breed: " + breed);
}
}
class Animal {
public static void main(String[] a) {
Dog obj = new Dog();
System.out.println("Riya Deshmankar " +
"2300290100212");
obj.display();
import java.util.Scanner;
public class Array {
public static void main(String[] s) {
Scanner sc = new Scanner(System.in);
int[][] arr = {
{1, 2, 3, 4},
{1, 2},
{1, 2, 3, 4, 5}
};
System.out.println("Riya Deshmankar"+" 2300290100212");
System.out.println("The elements of the 2D array are:");
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
sc.close();
}
}
Output
4. WAJP to check if a input "String" value is a palindrome or
not.
Output
import java.util.Scanner;
sc.close();
}
}