0% found this document useful (0 votes)
3 views1 page

Java Questions

The document contains Java programs for creating classes: 'Person' with attributes for name and age, 'Book' with attributes for title, author, and ISBN, and 'Employee' with attributes for name, title, and salary. Each class includes constructors and methods to set attributes and print them. The document also includes a placeholder for a method to remove a book from the 'Book' class.

Uploaded by

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

Java Questions

The document contains Java programs for creating classes: 'Person' with attributes for name and age, 'Book' with attributes for title, author, and ISBN, and 'Employee' with attributes for name, title, and salary. Each class includes constructors and methods to set attributes and print them. The document also includes a placeholder for a method to remove a book from the 'Book' class.

Uploaded by

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

write java program to create a class call person with nage and age attribute create

two instance of the person class set their attributes using constructed and print
their name and age
ANS:

import java.util.*;
class person{
String name;
int age;
public person(String name,int age){
this.name = name;
this.age = age;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("enter your Name: ");
String name = sc.nextLine();
System.out.println("enter your age: ");
int age = sc.nextInt();

person person = new person(name,age);


System.out.println("Name: "+person.name);
System.out.println("age: "+person.age);
}
}
write a java program to create aclass cale book with attributes for title,uthor and
ISBN also create method to add and remove books
ANS:
import java.util.*;
class Book{
String title;
String author;
int isbl;
public Book(String title,String author,int isbl){
this.title = title;
this.author = author;
this.isbl=isbl;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("enter title Of the book: ");
String title = sc.nextLine();
System.out.println("enter author of the book: ");
String author= sc.nextLine();
System.out.println("enter isbl: ");
int isbl = sc.nextInt();
Book book = new Book(title, author,isbl);
System.out.println("title: "+book.title);
System.out.println("author: "+book.author);
System.out.println("ISBL: "+book.isbl);
}
}
public remove element("book"){

write a java program tocreate a class employee with name joitle and salary
attributes and methods to calculate and update the salary

You might also like