Question: Practical: Lets put your knowledge into practice. Complete the following questions: Create a class named 'Student' with String variable 'name' and integer variable 'roll_no'. Assign

Practical:

Lets put your knowledge into practice. Complete the following questions:

Create a class named 'Student' with String variable 'name' and integer variable 'roll_no'. Assign the value of roll_no as '2' and that of name as "John" by creating an object of the class Student.

Assign and print the roll number, phone number and address of two students having names "Sam" and "John" respectively by creating two objects of class 'Student'.

Write a program to print the area of a rectangle by creating a class named 'Area' having two methods. First method named as 'setDim' takes length and breadth of rectangle as parameters and the second method named as 'getArea' returns the area of the rectangle. Length and breadth of rectangle are entered through keyboard.

Create a class named 'PrintNumber' to print various numbers of different datatypes by creating different methods with the same name 'printn' having a parameter for each datatype.

What is the output of this question?

class Test1 {

public

static void main(String[] args)

{

int x = 20;

System.out.println(x);

}

static

{

int x = 10;

System.out.print(x + " ");

}

}

Review:

Complete the following fill in the blank, True/False, Multiple Choice questions:

An object is an instance of a:_________

As a blueprint is a design for a house, a class is a design for a:_________

Variables which are defined without the STATIC keyword and are outside any method declaration are Object specific and are known as instance variables. _________True/ False

A static variable is common to all the instances (or objects) of the class because it is a class level variable. In other words you can say that only a single copy of static variable is created and shared among all the instances of the class.__________True/False

Which of these can be overloaded?

a) Methods

b) Constructors

c) All of the mentioned

d) None of the mentioned

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!