0% found this document useful (0 votes)
4 views5 pages

Java Basics: Classes, Variables, and Methods

The document outlines a Java programming course, covering topics such as the history of Java, data types, class declarations, and method overloading. It includes multiple-choice questions, programming exercises, and tasks related to variables, arrays, and string manipulation. Additionally, it emphasizes the use of inner classes and constructor overloading in Java.

Uploaded by

salomidasha
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)
4 views5 pages

Java Basics: Classes, Variables, and Methods

The document outlines a Java programming course, covering topics such as the history of Java, data types, class declarations, and method overloading. It includes multiple-choice questions, programming exercises, and tasks related to variables, arrays, and string manipulation. Additionally, it emphasizes the use of inner classes and constructor overloading in Java.

Uploaded by

salomidasha
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

Unit-1

Dr. B. Maddilety

Topic Number Topic name


1 History of Java, Java Virtual machine, Java buzzwords
2
Data types, variables, scope and lifetime of variables

Class declaration, Object declaration, Reference variables, garbage


3
collection, nested and inner classes

Constructors, static and this key words, Overloading methods and


4
constructors; Passing parameters to methods,
5 Arrays
6 Strings

1. Java programs must be recompiled for each platform.(True /False)

2. “Write Once, Run Anywhere” is a key feature of Java.( True/False)

3. In the below java programme what type of variable is declared and how can we
change to static variable

class Counter {

int count = 0;

void increment() {

count++;

4. Which variable is shared by all instances of a class?


a) Local
b) Instance
c) Static
d) Parameter

[Link] we run this method [Link](), what will happen in the back ground?
[Link] uses destructors to destroy objects.( True/False)

[Link] the below example is for what type nested class :

class Outer {

private String message = "Hello from Outer class";

class Inner {

void display() {

[Link](message); // Access outer class variable

public class Test {

public static void main(String[] args) {

Outer outer = new Outer();

[Link] a = [Link] Inner(); // Creating an inner class object

[Link]();

[Link] you justify the below programme is example for method overloading or
constructor overloading

class Printer {

public void print(int a) {

[Link]("Printing integer: " + a);

public void print(String s) {

[Link]("Printing string: " + s);

}
}

public class Main {

public static void main(String[] args) {

Printer printer = new Printer();

[Link](10); // Calls print(int a)

[Link]("Hello!"); // Calls print(String s)

17.

9.. Which of the following is an example of constructor overloading?


a) Two methods with same name but different return types
b) Two constructors with same name but different parameters
c) Two static methods with same name
d) Two methods with different names but same parameters

10. in the below programme can u find the error

public class ArrayExample {

public static void main(String[] args) {

int[] numbers = (10, 20, 30, 40, 50);

// Display the elements of the array

[Link]("Array elements:");

// Loop through the array and print each element

for (int i = 0; i < [Link]; i++) {

[Link](numbers[i]);

}
}

[Link] are immutable in Java in below example(True/False)

Programme:

public class StringImmutabilityExample {

public static void main(String[] args) {

String str1 = "Hello";

str1 = str1 + " World";

[Link]("Original String: " + str1); // Hello World

Section B:

[Link] are the different types of variables in Java? Explain their scope and lifetime with
examples.

[Link] a class Appointment to store patient name, doctor name, and date. Use inner class
Patient with fields for age and contact number. Demonstrate how inner class works by
creating an appointment object and calling inner class methods.

[Link] a class Product with id, name, and price. Use constructor overloading to
initialize different combinations of attributes. Use arrays to store 3 product objects and
display their details.

[Link] a Java program to count the number of vowels, consonants, digits, and special
characters in a given string.

[Link] are arrays created and accessed in Java?

Section c:

1. You are tasked with building a system to store the marks of 5 students in a class. After
storing their marks in an array, you need to:

a. Calculate the average marks.

B Find the highest and lowest marks.


[Link] the marks of all the students.

2. In many applications, users need to enter their email addresses during registration or
login. To ensure that the email is valid, we need to check if it follows the standard email
format (i.e., contains @, a domain name, and a proper extension like .com, .org, etc.).

We can use Strings in Java to validate the email input. Here's a simple Java
program that checks whether a given email address is valid or not.

You might also like