0
0
Javaprogramming~10 mins

Object creation in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new object of class Car.

Java
Car myCar = new [1]();
Drag options to blanks, or click blank then click option'
ACar
Bcar
CVehicle
Dnew
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase class name like 'car' instead of 'Car'.
Forgetting to use 'new' keyword.
2fill in blank
medium

Complete the code to create a new object of class Book with a constructor that takes a title.

Java
Book myBook = new Book([1]);
Drag options to blanks, or click blank then click option'
A123
BJava Basics
Ctitle
D"Java Basics"
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Not putting quotes around the string.
Passing a number instead of a string.
3fill in blank
hard

Fix the error in creating an object of class Person with no-argument constructor.

Java
Person p = [1] Person();
Drag options to blanks, or click blank then click option'
Amake
Bnew
Ccreate
DPerson
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Omitting the 'new' keyword.
Using other words like 'create' or 'make' which are not Java keywords.
4fill in blank
hard

Fill both blanks to create an object of class Student and call its method study.

Java
Student [1] = new [2]();
[1].study();
Drag options to blanks, or click blank then click option'
As
BStudent
Cstudent
Dstudy
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase for class name.
Using class name as variable name.
5fill in blank
hard

Fill all three blanks to create an object of class Laptop with brand and price, then print the brand.

Java
Laptop [1] = new [2]([3], 1200);
System.out.println([1].brand);
Drag options to blanks, or click blank then click option'
AmyLaptop
BLaptop
C"Dell"
Dbrand
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase for class name.
Not putting quotes around the brand string.